home *** CD-ROM | disk | FTP | other *** search
/ Delphi 4 Bible / Delphi_4_Bible_Tom_Swan_IDG_Books_1998.iso / source / DDECOLOR / CLIMAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1998-03-13  |  2KB  |  72 lines

  1. unit Climain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, DdeMan, StdCtrls, Buttons;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     DdeClientConv1: TDdeClientConv;
  12.     DdeClientItem1: TDdeClientItem;
  13.     Label1: TLabel;
  14.     Edit1: TEdit;
  15.     ColorValueLabel: TLabel;
  16.     BitBtn1: TBitBtn;
  17.     procedure DdeClientItem1Change(Sender: TObject);
  18.     procedure FormCreate(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   MainForm: TMainForm;
  27.  
  28. implementation
  29.  
  30. {$R *.DFM}
  31.  
  32. const
  33.   asciiBlank = ' ';  { One blank between two single quotes }
  34.  
  35. {- Client has received an item from server. Update sample
  36. color and label. }
  37. procedure TMainForm.DdeClientItem1Change(Sender: TObject);
  38. var
  39.   S: String;
  40.   C: TColor;
  41. begin
  42.   with DdeClientItem1 do
  43.   begin
  44.     if Length(Text) = 0 then
  45.       S := '$0'   { Default string }
  46.     else
  47.       S := Text;  { String from server }
  48.     try
  49.       while S[Length(S)] = asciiBlank do  { Delete trailing blanks }
  50.         System.Delete(S, Length(S), 1);   { from string. }
  51.       C := StringToColor(S);              { Convert to color }
  52.       ColorValueLabel.Caption := S;       { Assign to label }
  53.       Edit1.Color := C;                   { Show color }
  54.     except
  55.       ShowMessage('Bad color format from server');
  56.     end;
  57.   end;
  58. end;
  59.  
  60. {- Establish conversation with server. }
  61. procedure TMainForm.FormCreate(Sender: TObject);
  62. begin
  63.   if DdeClientConv1.SetLink('CSERVER', 'ColorServer') then
  64.   begin
  65.     DdeClientItem1.DdeItem := 'ColorItem';
  66.     if DdeClientConv1.ConnectMode = ddeManual then
  67.       DdeClientConv1.OpenLink;
  68.   end;
  69. end;
  70.  
  71. end.
  72.