⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pfgpalminf.pas

📁 delphi编写与Palm数据交换管道连接程序。
💻 PAS
字号:
unit pfgPalmInf;
{**************************************************************************}
{* pfgPalmInf Unit                                                        *}
{*                                                                        *}
{* This unit provides a set of information objects detailing information  *}
{* on the Palm. These objects aren't used by the conduit library, but are *}
{* rather intended as stand-alone objects for the user to reference in    *}
{* their conduits.                                                        *}
{*                                                                        *}
{* Currently available are:                                               *}
{*   PalmInfo object - This object provides basic information about the   *}
{*                     Palm and the current HotSync session.              *}
{*   CardInfo object - Submitted by Per-Eric Larsson 26/4/2001            *}
{*                     This object provides information about a           *}
{*                     specific Palm card (the CardInfo function returns  *}
{*                     information for card 0), including size, contents, *}
{*                     and the specific databases available.              *}
{*                                                                        *}
{* Copyright (C) 2001 by Paul Gilbert, All Rights Reserved                *}
{**************************************************************************}

interface

{$I pfgPalmConduits.inc}

{$IFDEF PFG_DELPHI6_UP}
uses Windows, Messages, SysUtils, Classes, pfgSyncMgr, Variants;
{$ELSE}
uses Windows, Messages, SysUtils, Classes, pfgSyncMgr;
{$ENDIF}

type
  TpfgPalmSystemInfo = class
  private
    FProductID: string;
    FMajor, FMinor: Integer;
    FUsername: string;
    FPassword: Variant;
    FLastSyncDate: TDateTime; // Only valid for Palm OS 3.0 or later
    FLastSyncPC: LongWord; // Only valid for Palm OS 3.0 or later
    FPCId: LongWord; // ID for this PC

    procedure Initialize;
  public
    constructor Create; virtual;

    property ProductID: string read FProductID;
    property Major: Integer read FMajor;
    property Minor: Integer read FMinor;
    property Username: string read FUsername;
    property Password: Variant read FPassword;
    property LastSyncDate: TDateTime read FLastSyncDate; // Valid for >= OS3.0
    property LastSyncPC: LongWord read FLastSyncPC;
    property PCId: LongWord read FPCId;
  end;

// PEL 2001-04-26

type
  TpfgDbInfo = class(TCollectionItem)
  private
    FModNumber: DWORD;
    FCreator: DWORD;
    FDbType: DWORD;
    FCardNum: Integer;
    FRecCount: longint;
    FDbName: string;
    FCreateDate: TDateTime;
    FBackupDate: TDateTime;
    FModDate: TDateTime;
    FDBIndex: WORD;
    FVersion: WORD;
    FDbFlags: WORD;
    procedure SetFromCDbList(const aCDbList: CDbList);
  protected
    function GetDisplayName: string; override;
  public
    constructor Create(Collection: TCollection); override;
    property CardNum: Integer read FCardNum;
    property DbFlags: WORD read FDbFlags;
    property DbType: DWORD read FDbType;
    property DbName: string read FDbName;
    property Creator: DWORD read FCreator;
    property Version: WORD read FVersion;
    property ModNumber: DWORD read FModNumber;
    property DBIndex: WORD read FDBIndex;
    property CreateDate: TDateTime read FCreateDate;
    property ModDate: TDateTime read FModDate;
    property BackupDate: TDateTime read FBackupDate;
    property RecCount: longint read FRecCount;
  end;

  TpfgDbInfoList = class(TCollection)
  private
    function GetDbItem(Index: Integer): TpfgDbInfo;
  public
    constructor Create; reintroduce;
    destructor Destroy; override;
    function Add(const aCDbList: CDbList): TpfgDbInfo;overload;
    function Add: TpfgDbInfo;overload;
    Procedure SendToStrings(ts:Tstrings);

    property Items[Index: Integer]: TpfgDbInfo read GetDbItem;
  end;

  TpfgCardInfo = class
  private
    FCardNo: Integer;
    FRomSize: DWORD;
    FCreateDate: TDateTime;
    FCardVersion: WORD;
    FFreeRam: DWORD;
    FRamSize: DWORD;
    FromDbCount: WORD;
    FramDbCount: WORD;
    FCardName: string;
    FManufName: string;
    FramDb: TpfgDbInfoList;
    FromDb: TpfgDbInfoList;
    procedure SetCardNo(const Value: Integer);
    procedure Initialize;
  public
    constructor Create; overload; virtual;
    constructor Create(acardno: Integer); overload; virtual;
    property CardNo: Integer read FCardNo write SetCardNo;
    property CardVersion: WORD read FCardVersion;
    property CreateDate: TDateTime read FCreateDate;
    property RomSize: DWORD read FRomSize;
    property RamSize: DWORD read FRamSize;
    property FreeRam: DWORD read FFreeRam;
    property romDbCount: WORD read FromDbCount;
    property ramDbCount: WORD read FramDbCount;
    property CardName: string read FCardName;
    property ManufName: string read FManufName;
    property romDb: TpfgDbInfoList read FromDb;
    property ramDb: TpfgDbInfoList read FramDb;
  end;

// PalmInfo
// Returns a global instance of the Palm info class

function PalmInfo: TpfgPalmSystemInfo;

// CardInfo
// Returns a global instance of the Card info class

function CardInfo: TpfgCardInfo;

implementation

uses
  pfgCondMgre,
  pfgPalmSyncError,
  pfgPalmMisc,
  PELDateTime;

var
  Int_PalmInfo: TpfgPalmSystemInfo = nil;
  Int_CardInfo: TpfgCardInfo = nil;

function PalmInfo: TpfgPalmSystemInfo;
begin
  if not Assigned(Int_PalmInfo) then Int_PalmInfo := TpfgPalmSystemInfo.Create;
  Result := Int_PalmInfo;
end;

function CardInfo: TpfgCardInfo;
begin
  if not Assigned(Int_CardInfo) then Int_CardInfo := TpfgCardInfo.Create;
  Result := Int_CardInfo;
end;

{**************************************************************************}
{* TpfgPalmSystemInfo class                                               *}
{*                                                                        *}
{**************************************************************************}

constructor TpfgPalmSystemInfo.Create;
begin
  Initialize;
end;

// Initialize
// Calls the SyncReadSystemInfo to get the Palm information, and then fills
// out the object's properties with the return values

procedure TpfgPalmSystemInfo.Initialize;
var
  info: CSystemInfo;
  Buffer: array[0..99] of Char;
  uinfo: CUserIDInfo;
  ctr: Integer;
begin
  { Get the basic system info }
  FillChar(info, Sizeof(CSystemInfo), 0);
  info.m_ProductIdText := @Buffer;
  info.m_AllocedLen := Sizeof(Buffer);
  PalmCheck(SyncReadSystemInfo(info));

  // Fill out the Product ID string
  SetLength(FProductID, info.m_ProdIdLength);
  Move(info.m_ProductIdText^, FProductID[1], info.m_ProdIdLength);

  // Fill out the ROM version
  FMajor := SYNCROMVMAJOR(info.m_RomSoftVersion);
  FMinor := SYNCROMVMINOR(info.m_RomSoftVersion);

  { Get the user info }
  FillChar(uinfo, Sizeof(uinfo), 0);
  PalmCheck(SyncReadUserID(uinfo));

  // Fill out the username
  FUsername := StrPas(uinfo.m_pName);

  // Fill out the password, storing it as a variant array
  FPassword := VarArrayCreate([0, uinfo.m_PasswdLength - 1], varByte);
  for ctr := 0 to uinfo.m_PasswdLength - 1 do FPassword[ctr] :=
    uinfo.m_Password[ctr];

  // Fill out the last sync date
  FLastSyncDate := UTCTimeToDateTime(uinfo.m_LastSyncDate);

  // Fill out the last synced PC ID
  FLastSyncPC := uinfo.m_LastSyncPC;

  // Find out this PC's ID
  PalmCheck(CmGetPCIdentifier(Integer(FPCId)));
end;


{ TpfgCardInfo }

constructor TpfgCardInfo.Create;
begin
  Create(0);
end;

constructor TpfgCardInfo.Create(acardno: Integer);
begin
  cardNo := Acardno;
  FramDb := TpfgDbInfoList.Create;
  FromDb := TpfgDbInfoList.Create;
  Initialize;
end;

procedure TpfgCardInfo.Initialize;
var
  rInfo: CCardInfo;
  CDbLista: array of CDbList;
  rCnt, i: Integer;
begin
  rInfo.m_CardNo := cardNo;
  rInfo.m_dwReserved := 0;
  PalmCheck(SyncReadSingleCardInfo(rInfo));
  FManufName := strpas(rInfo.m_ManufName);
  setlength(FManufName,rInfo.m_ManufNameLen);
  FCardName := strpas(rInfo.m_CardName);
  setlength(FCardName,rInfo.m_CardNameLen);
  FCreateDate := UTCTimeToDateTime(rInfo.m_CreateDate);
  FCardVersion := rInfo.m_CardVersion;
  FFreeRam := rInfo.m_FreeRam;
  FRamSize := rInfo.m_RamSize;
  FRomSize := rInfo.m_RomSize;

//rom db's
  FromDbCount := rInfo.m_romDbCount;
  rCnt := romDbCount;
  setlength(CDbLista, rCnt);
  PalmCheck(SyncReadDBList(cardNo, 0, false, @CDbLista[0], rCnt));
  for i := 0 to romDbCount - 1 do
  begin
    FromDb.Add(CDbLista[i]);
  end;
  FramDbCount := rInfo.m_ramDbCount;
  rCnt := ramDbCount;
  setlength(CDbLista, rCnt);
  PalmCheck(SyncReadDBList(cardNo, 0, true, @CDbLista[0], rCnt));
  for i := 0 to ramDbCount - 1 do
  begin
    FramDb.Add(CDbLista[i]);
  end;
end;

procedure TpfgCardInfo.SetCardNo(const Value: Integer);
begin
  FCardNo := Value;
end;


{ TpfgDbInfo }

constructor TpfgDbInfo.Create(Collection: TCollection);
begin
  inherited;
end;

procedure TpfgDbInfo.SetFromCDbList(const aCDbList: CDbList);
begin
  FModNumber := aCDbList.m_ModNumber;
  FCreator := aCDbList.m_Creator;
  FDbType := aCDbList.m_DbType;
  FCardNum:= aCDbList.m_CardNum;
  FRecCount:= aCDbList.m_RecCount;
  FDbName:= strpas(aCDbList.m_Name);
  FCreateDate := UTCTimeToDateTime(aCDbList.m_CreateDate);
  FBackupDate := UTCTimeToDateTime(aCDbList.m_BackupDate);
  FModDate := UTCTimeToDateTime(aCDbList.m_ModDate);
  FDBIndex := aCDbList.m_Index;
  FVersion := aCDbList.m_Version;
  FDbFlags := aCDbList.m_DbFlags;
end;

function TpfgDbInfo.GetDisplayName: string;
begin
  Result := DbName;
end;

{ TpfgDbInfoList }

function TpfgDbInfoList.Add: TpfgDbInfo;
begin
  Result := inherited Add as TpfgDbInfo;
end;


function TpfgDbInfoList.Add(const aCDbList: CDbList): TpfgDbInfo;
begin

  Result := self.Add;
  result.SetFromCDbList(aCDbList);
end;


constructor TpfgDbInfoList.Create;
begin
  inherited Create(TpfgDbInfo);
end;

destructor TpfgDbInfoList.Destroy;
begin
  inherited;
end;

procedure TpfgDbInfoList.SendToStrings(ts: Tstrings);
var
  i:integer;
begin
  ts.BeginUpdate;
  ts.clear;
  for i := 0 to Count-1 do
  begin
    ts.Add(items[i].DisplayName);
  end;
  ts.EndUpdate;
end;

// GetDbItem
// Returns an item from the collection, cast to a TpfgDbInfo class

function TpfgDbInfoList.GetDbItem(Index: Integer): TpfgDbInfo;
begin
  Result := inherited Items[Index] as TpfgDbInfo;
end;

initialization

finalization
begin
  if Assigned(Int_PalmInfo) then Int_PalmInfo.Free;
  if Assigned(Int_CardInfo) then Int_CardInfo.Free;  
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -