home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
DDEREG.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-02-28
|
6KB
|
247 lines
unit DDEReg;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, Buttons, TypInfo,
DsgnIntf, DdeMan, Messages, StdCtrls, LibMain, ExtCtrls;
{ TComponentEditors }
type
TSrvrConvEdit = class(TDefaultEditor)
protected
procedure EditProperty(PropertyEditor: TPropertyEditor;
var Continue, FreeEditor: Boolean); override;
end;
TCliConvEdit = class(TDefaultEditor)
protected
procedure EditProperty(PropertyEditor: TPropertyEditor;
var Continue, FreeEditor: Boolean); override;
end;
TSrvrItemEdit = class(TDefaultEditor)
public
procedure Copy; override;
end;
{ TForms }
type
TDdeLinkDlg = class(TForm)
TopicEdit: TEdit;
AppEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
OK: TButton;
CancelBtn: TButton;
PasteBtn: TButton;
HelpBtn: TButton;
procedure doPasteLink(Sender: TObject);
procedure DoPasteCheck(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure HelpBtnClick(Sender: TObject);
private
procedure WMActivate(var Message: TWMActivate); message WM_ACTIVATE;
end;
TDdeLinkInfoProperty = class(TPropertyEditor)
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
function GetValue: string; override;
end;
TDdeClientItemProperty = class(TStringProperty)
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
end;
{ Dde Helper Delegate }
TLibDde = class (TLibDdeHelper)
public
procedure SetProjectName (Name : String); override;
end;
procedure Register;
{}
implementation
uses Dialogs, LibConst, Consts, LibHelp;
{$R *.DFM}
{---------------------------------------}
procedure TSrvrConvEdit.EditProperty(PropertyEditor: TPropertyEditor;
var Continue, FreeEditor: Boolean);
var
PropName: string;
begin
PropName := PropertyEditor.GetName;
if (CompareText(PropName, 'ONEXECUTEMACRO') = 0) then
begin
PropertyEditor.Edit;
Continue := False;
end
else
inherited EditProperty(PropertyEditor, Continue, FreeEditor);
end;
procedure TCliConvEdit.EditProperty(PropertyEditor: TPropertyEditor;
var Continue, FreeEditor: Boolean);
var
PropName: string;
begin
PropName := PropertyEditor.GetName;
if (CompareText(PropName, 'ONOPEN') = 0) then
begin
PropertyEditor.Edit;
Continue := False;
end
else
inherited EditProperty(PropertyEditor, Continue, FreeEditor);
end;
procedure TSrvrItemEdit.Copy;
begin
TDdeServerItem(Component).CopyToClipboard;
end;
{---------------------------------------}
{ TDdeLinkInfoProperty }
function TDdeLinkInfoProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog, paReadOnly]
- [paMultiSelect, paSubProperties];
end;
function TDdeLinkInfoProperty.GetValue: string;
begin
if GetStrValue = '' then Result := LoadStr(SDdeEmptyConnection)
else Result := Format ('(%s)', [GetStrValue]);
end;
procedure TDdeLinkInfoProperty.Edit;
var
DdeCli : TDdeClientConv;
LinkDlg : TDdeLinkDlg;
begin
DdeCli := TDdeClientConv (GetComponent(0));
LinkDlg := TDdeLinkDlg.Create(Application);
try
LinkDlg.AppEdit.Text := DdeCli.DdeService;
LinkDlg.TopicEdit.Text := DdeCli.DdeTopic;
if LinkDlg.ShowModal = idOk then
begin
if Not DdeCli.SetLink(LinkDlg.AppEdit.Text,
LinkDlg.TopicEdit.Text) then
MessageDlg(LoadStr(SDdeNoConnect), mtError, [mbOK], 0);
Modified;
end;
finally
LinkDlg.Free;
end;
end;
{---------------------------------------}
procedure TDdeLinkDlg.doPasteLink(Sender: TObject);
var
Service, Topic, Item : String;
begin
if GetPasteLinkInfo (Service, Topic, Item) = True then
begin
AppEdit.Text := Service;
TopicEdit.Text := Topic;
end
else
begin
AppEdit.Text := EmptyStr;
TopicEdit.Text := EmptyStr;
end;
end;
procedure TDdeLinkDlg.DoPasteCheck(Sender: TObject);
var
enable : Boolean;
Service, Topic, Item : String;
begin
enable := False;
if GetPasteLinkInfo (Service, Topic, Item) = True then
enable := True;
if enable <> PasteBtn.Enabled then
PasteBtn.Enabled := enable;
end;
procedure TDdeLinkDlg.WMActivate(var Message: TWMActivate);
begin
inherited;
if Message.Active <> WA_INACTIVE then DoPasteCheck(Self);
end;
procedure TDdeLinkDlg.FormCreate(Sender: TObject);
begin
HelpContext := hcDDDEInfo;
end;
procedure TDdeLinkDlg.HelpBtnClick(Sender: TObject);
begin
Application.HelpContext(HelpContext);
end;
{-------}
{ TDdeClientItemProperty }
function TDdeClientItemProperty.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paValueList] - [paMultiSelect,
paSubProperties];
end;
procedure TDdeClientItemProperty.GetValues(Proc: TGetStrProc);
var
Cli : TDdeClientConv;
Service, Topic, Item : String;
begin
Cli := TDdeClientConv(TDdeClientItem (GetComponent(0)).DdeConv);
if Cli <> Nil then
begin
if GetPasteLinkInfo (Service, Topic, Item) = True then
begin
if (Service = Cli.DdeService) and
(Topic = Cli.DdeTopic) then
Proc (Item);
end;
end;
end;
{---------------------------------------}
procedure TLibDde.SetProjectName (Name : String);
begin
if Length (Name) <> 0 then
ddeMgr.AppName := Name
else
ddeMgr.AppName := ddeMgr.GetExeName;
end;
{---------------------------------------}
procedure Register;
begin
LibDdeHelper := TLibDde.Create;
RegisterComponents(LoadStr(srSystem),
[TDdeClientConv, TDdeClientItem, TDdeServerConv, TDdeServerItem]);
RegisterPropertyEditor(TypeInfo(string), TDdeClientConv, 'DdeService', TDdeLinkInfoProperty);
RegisterPropertyEditor(TypeInfo(string), TDdeClientConv, 'DdeTopic', TDdeLinkInfoProperty);
RegisterPropertyEditor(TypeInfo(string), TDdeClientItem, 'DdeItem', TDdeClientItemProperty);
RegisterComponentEditor(TDdeServerItem, TSrvrItemEdit);
RegisterComponentEditor(TDdeServerConv, TSrvrConvEdit);
RegisterComponentEditor(TDdeClientConv, TCliConvEdit);
end;
end.