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

📄 pfgpalmsyncwizzard.pas

📁 delphi编写与Palm数据交换管道连接程序。
💻 PAS
字号:
unit pfgPalmSyncWizzard;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  StdCtrls,
  ExtCtrls,
  db,
  pfgpalmdb,
  pfgPalmSyncComponent;

type
  TPalmSyncWizzardForm = class(TForm)
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    Splitter1: TSplitter;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Panel5: TPanel;
    Panel7: TPanel;
    Panel10: TPanel;
    Panel12: TPanel;
    Panel13: TPanel;
    Panel14: TPanel;
    Panel15: TPanel;
    PalmTableListBox: TListBox;
    Panel1: TPanel;
    Panel6: TPanel;
    LocalFieldListBox: TListBox;
    OkButton: TButton;
    CopyPCButton: TButton;
    CopyPalmButton: TButton;
    Panel8: TPanel;
    Panel9: TPanel;
    Panel11: TPanel;
    ClearLocalFieldsButton: TButton;
    ClearPalmFieldsButton: TButton;
    Panel18: TPanel;
    GroupBox4: TGroupBox;
    Panel19: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    RecordIDComboBox: TComboBox;
    CategoryComboBox: TComboBox;
    GroupBox3: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    AttributesComboBox: TComboBox;
    DirtyComboBox: TComboBox;
    DeletedComboBox: TComboBox;
    Splitter2: TSplitter;
    procedure FormActivate(Sender: TObject);
    procedure RecordIDComboBoxDropDown(Sender: TObject);
    procedure CategoryComboBoxDropDown(Sender: TObject);
    procedure AttributesComboBoxDropDown(Sender: TObject);
    procedure DirtyComboBoxDropDown(Sender: TObject);
    procedure DeletedComboBoxDropDown(Sender: TObject);
    procedure AttributesComboBoxChange(Sender: TObject);
    procedure DirtyComboBoxChange(Sender: TObject);
    procedure DeletedComboBoxChange(Sender: TObject);
    procedure CopyPalmButtonClick(Sender: TObject);
    procedure ClearPalmFieldsButtonClick(Sender: TObject);
    procedure ClearLocalFieldsButtonClick(Sender: TObject);
    procedure OkButtonClick(Sender: TObject);
  private
    procedure GetLocalFieldNames(ts: Tstrings);
    procedure GetLocalBooleanFieldNames(ts: Tstrings);
    procedure GetLocalNumericFieldNames(ts: Tstrings);
    procedure GetPalmFieldNames(ts: Tstrings);
    { Private declarations }
  public
    { Public declarations }
    AComponent: TpfgPalmSyncComponent;
//    LocalFields: TFields;
//    pfgPalmFields: TpfgPalmFields;
  end;

function ShowPalmSyncWizzard(Component: TpfgPalmSyncComponent): integer;

var
  PalmSyncWizzardForm: TPalmSyncWizzardForm;

implementation
{$R *.DFM}

//function PalmFieldTypeToFieldType(AType: TpfgPalmFieldType): TFieldType;
//begin
//  raise ENotImplError.Create('PalmFieldTypeToFieldType');
////  Result := ptInteger; //
//end;

function FieldTypeToPalmFieldType(AType: TFieldType): TpfgPalmFieldType;
begin
  case AType of
    ftString: Result := ptString;
    ftSmallInt, ftWord: Result := ptWord;
    ftDate, ftDateTime: Result := ptDate;
    ftTime: Result := ptTime;
    ftInteger: Result := ptLong;
    ftBoolean: Result := ptLong;
  else
    raise ENotImplError.Create('FieldTypeToPalmFieldType');
  end;
end;

function ShowPalmSyncWizzard(Component: TpfgPalmSyncComponent): integer;
begin
  if assigned(Component.LocalDataSet) and
    assigned(Component.pfgPalmRemoteTable) then
  begin
    PalmSyncWizzardForm := TPalmSyncWizzardForm.Create(Application);
    try

      PalmSyncWizzardForm.AComponent := Component;
      result := PalmSyncWizzardForm.ShowModal;
      if result = mrOk then
      begin
      end;
    finally
      PalmSyncWizzardForm.free;
    end;
  end else begin
    showmessage('You must assign propertys "LocalDataSet" and "pfgPalmRemoteTable" to use the PalmSyncWizzard');
    result:=mrcancel;
  end;
end;



procedure TPalmSyncWizzardForm.FormActivate(Sender: TObject);
begin
  GetLocalFieldNames(LocalFieldListBox.Items);
  GetPalmFieldNames(PalmTableListBox.items);
  try
    RecordIDComboBox.text := AComponent.LocalRecIdField.FieldName;
  except
    RecordIDComboBox.text := '';
  end;
  try
    CategoryComboBox.text := AComponent.LocalCategoryField.FieldName;
  except
    CategoryComboBox.text := '';
  end;
  try
    DirtyComboBox.text := AComponent.LocalDirtyField.FieldName;
  except
    DirtyComboBox.text := '';
  end;
  try
    DeletedComboBox.text := AComponent.LocalDeletedField.FieldName;
  except
    DeletedComboBox.text := '';
  end;
end;

procedure TPalmSyncWizzardForm.GetPalmFieldNames(ts: Tstrings);
var
  i: integer;
begin
  ts.beginupdate;
  ts.Clear;
  for i := 0 to AComponent.pfgPalmRemoteTable.Fields.count - 1 do
  begin
    ts.add(AComponent.pfgPalmRemoteTable.Fields[i].FieldName);
  end;
  ts.EndUpdate;
end;

procedure TPalmSyncWizzardForm.GetLocalFieldNames(ts: Tstrings);
var
  i: integer;
begin
  ts.beginupdate;
  ts.Clear;
  for i := 0 to AComponent.LocalDataSet.Fields.count - 1 do
  begin
    ts.add(AComponent.LocalDataSet.Fields[i].FieldName);
  end;
  ts.EndUpdate;
end;

procedure TPalmSyncWizzardForm.GetLocalBooleanFieldNames(ts: Tstrings);
var
  i: integer;
begin
  ts.beginupdate;
  ts.Clear;
  for i := 0 to AComponent.LocalDataSet.Fields.count - 1 do
  begin
    if AComponent.LocalDataSet.Fields[i] is TBooleanField then
    begin
      ts.add(AComponent.LocalDataSet.Fields[i].FieldName);
    end;
  end;
  ts.EndUpdate;
end;

procedure TPalmSyncWizzardForm.GetLocalNumericFieldNames(ts: Tstrings);
var
  i: integer;
begin
  ts.beginupdate;
  ts.Clear;
  for i := 0 to AComponent.LocalDataSet.Fields.count - 1 do
  begin
    if AComponent.LocalDataSet.Fields[i] is TnumericField then
    begin
      ts.add(AComponent.LocalDataSet.Fields[i].FieldName);
    end;
  end;
  ts.EndUpdate;
end;

procedure TPalmSyncWizzardForm.RecordIDComboBoxDropDown(Sender: TObject);
begin
  GetLocalNumericFieldNames(RecordIDComboBox.Items);
end;

procedure TPalmSyncWizzardForm.CategoryComboBoxDropDown(Sender: TObject);
begin
  GetLocalNumericFieldNames(CategoryComboBox.Items);
end;

procedure TPalmSyncWizzardForm.AttributesComboBoxDropDown(Sender: TObject);
begin
  GetLocalNumericFieldNames(AttributesComboBox.Items);
end;

procedure TPalmSyncWizzardForm.DirtyComboBoxDropDown(Sender: TObject);
begin
  GetLocalBooleanFieldNames(DirtyComboBox.Items);
end;

procedure TPalmSyncWizzardForm.DeletedComboBoxDropDown(Sender: TObject);
begin
  GetLocalBooleanFieldNames(DeletedComboBox.items);
end;

procedure TPalmSyncWizzardForm.AttributesComboBoxChange(Sender: TObject);
begin
  if AttributesComboBox.Text <> '' then
  begin
    DirtyComboBox.text := '';
    DeletedComboBox.text := '';
  end;
end;

procedure TPalmSyncWizzardForm.DirtyComboBoxChange(Sender: TObject);
begin
  if DirtyComboBox.Text <> '' then
  begin
    AttributesComboBox.text := '';
  end;
end;

procedure TPalmSyncWizzardForm.DeletedComboBoxChange(Sender: TObject);
begin
  if DeletedComboBox.text <> '' then
  begin
    AttributesComboBox.text := '';
  end;
end;

procedure TPalmSyncWizzardForm.CopyPalmButtonClick(Sender: TObject);
var
  i: integer;
  s: string;
begin
  for i := 0 to AComponent.LocalDataSet.Fields.count - 1 do
  begin
    s := AComponent.LocalDataSet.Fields[i].FieldName;
    if (s <> AttributesComboBox.Text)
      and (s <> RecordIDComboBox.text)
      and (s <> DirtyComboBox.text)
      and (s <> DeletedComboBox.text)
      and (s <> CategoryComboBox.Text) then
    begin
      AComponent.pfgPalmRemoteTable.FieldDefs.Add(s,
        FieldTypeToPalmFieldType(AComponent.LocalDataSet.Fields[i].DataType),
        0);
    end;
  end;
  GetPalmFieldNames(PalmTableListBox.items);
end;

procedure TPalmSyncWizzardForm.ClearPalmFieldsButtonClick(Sender: TObject);
begin
  AComponent.pfgPalmRemoteTable.FieldDefs.Clear;
  GetPalmFieldNames(PalmTableListBox.items);
end;

procedure TPalmSyncWizzardForm.ClearLocalFieldsButtonClick(
  Sender: TObject);
begin
  AComponent.LocalDataSet.Fields.Clear;
  GetLocalFieldNames(LocalFieldListBox.Items);
end;

procedure TPalmSyncWizzardForm.OkButtonClick(Sender: TObject);
begin
  try
    AComponent.LocalRecIdField :=
      TnumericField(AComponent.LocalDataSet.Fieldbyname(RecordIDComboBox.text));
  except
    AComponent.LocalRecIdField := nil;
  end;
  try
    AComponent.LocalAttribsField :=
      TnumericField(AComponent.LocalDataSet.Fieldbyname(CategoryComboBox.Text));
  except
    AComponent.LocalAttribsField := nil;
  end;
  try
    AComponent.LocalAttribsField :=
      TnumericField(AComponent.LocalDataSet.Fieldbyname(AttributesComboBox.Text));
  except
  end;
  try
    AComponent.LocalDirtyField :=
      TBooleanField(AComponent.LocalDataSet.Fieldbyname(DirtyComboBox.text));
  except
    AComponent.LocalDirtyField := nil;
  end;
  try
    AComponent.LocalDeletedField :=
      TBooleanField(AComponent.LocalDataSet.Fieldbyname(DeletedComboBox.text));
  except
    AComponent.LocalDeletedField := nil;
  end;
end;

end.

⌨️ 快捷键说明

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