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

📄 pfghotsyncaction.pas

📁 delphi编写与Palm数据交换管道连接程序。
💻 PAS
字号:
unit pfgHotSyncAction;
{**************************************************************************}
{* pfgHotSyncAction Unit                                                  *}
{*                                                                        *}
{* This unit defines the TpfgHotSyncActionDialog class, which provides a  *}
{* HotSync Action Dialog similiar to that provided by the CDK for Visual  *}
{* C++.                                                                   *}
{*                                                                        *}
{* Copyright (C) 2000-2002 by Paul Gilbert, All Rights Reserved           *}
{**************************************************************************}

interface

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

type
  TpfgRadioItemArray = array [0..3] of TRadioButton;

  TpfgHotSyncActionForm = class(TForm)
    GBActions: TGroupBox;
    BtnOk: TButton;
    BtnCancel: TButton;
    BtnHelp: TButton;
    RBSyncFiles: TRadioButton;
    RBPCtoHH: TRadioButton;
    RBHHtoPC: TRadioButton;
    RBDoNothing: TRadioButton;
    CBSetAsDefault: TCheckBox;
    Image1: TImage;
    Image2: TImage;
    Image3: TImage;
    Image4: TImage;
    BtnData: TButton;
    BtnAbout: TButton;
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    FArray: TpfgRadioItemArray;
    function GetItemEnabled(Index: Integer): Boolean;
    procedure SetItemEnabled(Index: Integer; AEnabled: Boolean);
    function GetHSAction: Integer;
    procedure SetHSAction(Index: Integer);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    property ItemEnabled[Index: Integer]: Boolean read GetItemEnabled
      write SetItemEnabled;
    property HsAction: Integer read GetHsAction write SetHsAction;
  end;


  TpfgHotSyncActionDialog = class(TComponent)
  private
    FActionEnableds: Array [0..3] of Boolean;
    FConduitName: string;
    FActionIndex: Integer;
    FSetAsDefault: Boolean;
    FBtnDataCaption: String;
    FOnBtnDataClick: TNotifyEvent;
    FBtnAboutCaption: String;
    FOnBtnAboutClick: TNotifyEvent;

    function GetActionEnabled(Index: Integer): Boolean;
    procedure SetActionEnabled(Index: Integer; Value: Boolean);
  published
    property ConduitName: string read FConduitName write FConduitName;
    property ActionIndex: Integer read FActionIndex write FActionIndex;
    property BtnAboutCaption: string read FBtnAboutCaption write FBtnAboutCaption;
    property OnBtnAboutClick: TNotifyEvent read FOnBtnAboutClick write FOnBtnAboutClick;
    property BtnDataCaption: string read FBtnDataCaption write FBtnDataCaption;
    property OnBtnDataClick: TNotifyEvent read FOnBtnDataClick write FOnBtnDataClick;
  public
    constructor Create(AOwner: TComponent); override;
    function Execute: Boolean;

    procedure DoBtnDataClick;
    procedure DoBtnAboutClick;

    property SetAsDefault: Boolean read FSetAsDefault;
    property ActionEnabled[Index: Integer]: Boolean read GetActionEnabled
      write SetActionEnabled;
  end;

var
  pfgHotSyncActionForm: TpfgHotSyncActionForm;

implementation

{$R *.DFM}

resourcestring
  SIndexError = 'Invalid index to ActionEnabled property';

{**************************************************************************}

constructor TpfgHotSyncActionForm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FArray[0] := RBSyncFiles; FArray[1] := RBPCtoHH;
  FArray[2] := RBHHtoPC;    FArray[3] := RBDoNothing;
end;

function TpfgHotSyncActionForm.GetItemEnabled(Index: Integer): Boolean;
begin
  if (Index < 0) or (Index > 3) then raise Exception.Create(SIndexError);
  Result := FArray[Index].Enabled;
end;

procedure TpfgHotSyncActionForm.SetItemEnabled(Index: Integer; AEnabled: Boolean);
begin
  if (Index < 0) or (Index > 3) then raise Exception.Create(SIndexError);
  FArray[Index].Enabled := AEnabled;
end;

function TpfgHotSyncActionForm.GetHSAction: Integer;
var
  ctr: Integer;
begin
  for ctr := 0 to 3 do
    if FArray[ctr].Checked then
    begin
      Result := ctr;
      Exit;
    end;
  Result := -1;
end;

procedure TpfgHotSyncActionForm.SetHSAction(Index: Integer);
var
  ctr: Integer;
begin
  if (Index < 0) or (Index > 3) then raise Exception.Create(SIndexError);
  if FArray[Index].Enabled then FArray[Index].Checked := True
  else
  begin
    // Selected action is disabled, select first enabled one
    for ctr := 0 to 3 do
      if FArray[ctr].Enabled then
      begin
        FArray[ctr].Checked := True;
        Exit;
      end;
  end;
end;

procedure TpfgHotSyncActionForm.FormShow(Sender: TObject);
begin
  if BtnAbout.Visible And BtnData.Visible then
  begin
    BtnAbout.Top:=GBActions.Top+GBActions.Height-BtnAbout.Height;
    BtnData.Top:=BtnAbout.Top-BtnData.Height-6;
  end
  else
  if BtnAbout.Visible then
    BtnAbout.Top:=GBActions.Top+GBActions.Height-BtnAbout.Height
  else
  if BtnData.Visible then
    BtnData.Top:=GBActions.Top+GBActions.Height-BtnData.Height;
end;

{**************************************************************************}

constructor TpfgHotSyncActionDialog.Create(AOwner: TComponent);
var
  ctr: Integer;
begin
  inherited Create(AOwner);

  for ctr := 0 to 3 do FActionEnableds[ctr] := True;
  FConduitName := '';
  FActionIndex := 0; // Sync files
  FSetAsDefault:= False;
  FBtnDataCaption:='Data settings';
  FOnBtnDataClick:=Nil;
  FBtnAboutCaption:='About';
  FOnBtnAboutClick:=Nil;
end;

function TpfgHotSyncActionDialog.GetActionEnabled(Index: Integer): Boolean;
begin
  if (Index < 0) or (Index > 3) then raise Exception.Create(SIndexError);
  Result := FActionEnableds[Index];
end;

procedure TpfgHotSyncActionDialog.SetActionEnabled(Index: Integer; Value: Boolean);
begin
  if (Index < 0) or (Index > 3) then raise Exception.Create(SIndexError);
  FActionEnableds[Index] := Value;
end;


function TpfgHotSyncActionDialog.Execute: Boolean;
var
  ctr: Integer;
begin
  with TpfgHotSyncActionForm.Create(nil) do
    try
      // Set which readio buttons are enabled
      for ctr := 0 to 3 do ItemEnabled[ctr] := FActionEnableds[ctr];
      // Set the radio button to use
      HsAction := FActionIndex;
      // Set the Conduit Name
      if FConduitName <> '' then
        GBActions.Caption := GBActions.Caption + FConduitName
      else
        GBActions.Caption := GBActions.Caption + 'Untitled';

      // Set the Data buttons properties
      if Assigned(FOnBtnDataClick) then
      begin
        BtnData.OnClick:=FOnBtnDataClick;
        if Trim(FBtnDataCaption)<>'' then
          BtnData.Caption:=FBtnDataCaption
        else
          BtnData.Caption:='Data settings';
        BtnData.Visible:=True;
      end;

      // Set the About buttons properties
      if Assigned(FOnBtnAboutClick) then
      begin
        BtnAbout.OnClick:=FOnBtnAboutClick;
        if Trim(FBtnAboutCaption)<>'' then
          BtnAbout.Caption:=FBtnAboutCaption
        else
          BtnAbout.Caption:='About';
        BtnAbout.Visible:=True;
      end;

      // Show the dialog
      Result := ShowModal = mrOk;

      if Result then
      begin
        // if a successfull result, then fill out the result information
        FActionIndex := HsAction;
        FSetAsDefault := CBSetAsDefault.Checked;
      end;

    finally
      Free;
    end;
end;

procedure TpfgHotSyncActionDialog.DoBtnAboutClick;
begin
  if Assigned(FOnBtnAboutClick) then FOnBtnAboutClick(Self);
end;

procedure TpfgHotSyncActionDialog.DoBtnDataClick;
begin
  if Assigned(FOnBtnDataClick) then FOnBtnDataClick(Self);
end;

end.

⌨️ 快捷键说明

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