home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / tpw / docdemos / trantest.pas < prev    next >
Pascal/Delphi Source File  |  1991-05-20  |  4KB  |  125 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Demo program                                 }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program TranApp;
  10.  
  11. {$R TRANTEST.RES }
  12.  
  13. uses WObjects, WinTypes, WinProcs, Strings;
  14.  
  15. const
  16.   cm_MenuTest      = 399;
  17.   id_AddressStatic = 101;
  18.   id_MrButton      = 102;
  19.   id_MsButton      = 103;
  20.   id_DrButton      = 104;
  21.   id_NameEdit      = 106;
  22.   id_Address1Edit  = 107;
  23.   id_Address2Edit  = 108;
  24.   id_CityStateEdit = 109;
  25.   id_CountryEdit   = 110;
  26.  
  27. type
  28.   TransferAddressRecord = record
  29.     AddressStatic: array[0..40] of Char;
  30.     MrTitle: Bool;
  31.     MsTitle: Bool;
  32.     DrTitle: Bool;
  33.     NameEdit: array[0..40] of Char;
  34.     Address1Edit: array[0..40] of Char;
  35.     Address2Edit: array[0..40] of Char;
  36.     CityStateEdit: array[0..40] of Char;
  37.     CountryEdit: array[0..40] of Char;
  38.   end;
  39.  
  40.   { TransferApplication type declaration. }
  41.   TransferApplication = object(TApplication)
  42.     procedure InitMainWindow; virtual;
  43.   end;
  44.  
  45.   { TransferWindow type declaration. }
  46.   PTransferWindow = ^TransferWindow;
  47.   TransferWindow = object(TWindow)
  48.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  49.     procedure Test(var Msg: TMessage); virtual cm_First + cm_MenuTest;
  50.   end;
  51.  
  52. var
  53.   MyApp: TransferApplication;
  54.  
  55. { Constructor; init each child control. }
  56. constructor TransferWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  57. begin
  58.   TWindow.Init(AParent, ATitle);
  59.   Attr.Menu := LoadMenu(HInstance, PChar(cm_MenuTest));
  60. end;
  61.  
  62. { Init the main window of a TransferApplication - an TransferWindow. }
  63. procedure TransferApplication.InitMainWindow;
  64. begin
  65.   MainWindow := New(PTransferWindow, Init(nil, 'Test Dialog Transfer'));
  66. end;
  67.  
  68. procedure TransferWindow.Test(var Msg: TMessage);
  69. const
  70.   AddressRecord: TransferAddressRecord = (
  71.     AddressStatic: 'First Mailing Label';
  72.     MrTitle: True;
  73.     MsTitle: False;
  74.     DrTitle: False);
  75.   NewLine = #13#10;
  76. var
  77.   D: PDialog;
  78.   S1: PStatic;
  79.   R1: PRadioButton;
  80.   E1: PEdit;
  81.   ReturnValue: Integer;
  82.   ALabel: array[0..255] of Char;
  83. begin
  84.   D := New(PDialog, Init(@Self, PChar(100)));
  85.   New(S1, InitResource(D, id_AddressStatic, SizeOf(AddressRecord.AddressStatic)));
  86.   New(R1, InitResource(D, id_MrButton));
  87.   New(R1, InitResource(D, id_MsButton));
  88.   New(R1, InitResource(D, id_DrButton));
  89.   New(E1, InitResource(D, id_NameEdit, SizeOf(AddressRecord.NameEdit)));
  90.   New(E1, InitResource(D, id_Address1Edit, SizeOf(AddressRecord.Address1Edit)));
  91.   New(E1, InitResource(D, id_Address2Edit, SizeOf(AddressRecord.Address2Edit)));
  92.   New(E1, InitResource(D, id_CityStateEdit, SizeOf(AddressRecord.CityStateEdit)));
  93.   New(E1, InitResource(D, id_CountryEdit, SizeOf(AddressRecord.CountryEdit)));
  94.   D^.TransferBuffer := @AddressRecord;
  95.   ReturnValue := Application^.ExecDialog(D);
  96.   if ReturnValue = idCancel then
  97.     MessageBox(HWindow, 'Cancelled', 'AddressDialog', 0)
  98.   else
  99.   begin
  100.     StrCopy(ALabel, 'Mailing Label Entered:');
  101.     StrLCat(ALabel, NewLine, SizeOf(ALabel));
  102.     StrLCat(ALabel, NewLine, SizeOf(ALabel));
  103.     StrLCat(ALabel, AddressRecord.NameEdit, SizeOf(ALabel));
  104.     StrLCat(ALabel, NewLine, SizeOf(ALabel));
  105.     StrLCat(ALabel, AddressRecord.Address1Edit, SizeOf(ALabel));
  106.     StrLCat(ALabel, NewLine, SizeOf(ALabel));
  107.     if StrComp(AddressRecord.Address2Edit, '') <> 0 then
  108.     begin
  109.       StrLCat(ALabel, AddressRecord.Address2Edit, SizeOf(ALabel));
  110.       StrLCat(ALabel, NewLine, SizeOf(ALabel));
  111.     end;
  112.     StrLCat(ALabel, AddressRecord.CityStateEdit, SizeOf(ALabel));
  113.     StrLCat(ALabel, NewLine, SizeOf(ALabel));
  114.     StrLCat(ALabel, AddressRecord.CountryEdit, SizeOf(ALabel));
  115.     MessageBox(HWindow, ALabel, 'Test Dialog Transfer', mb_Ok);
  116.     StrCopy(AddressRecord.AddressStatic, 'Subsequent Mailing Labels');
  117.   end;
  118. end;
  119.  
  120. begin
  121.   MyApp.Init('TranApp');
  122.   MyApp.Run;
  123.   MyApp.Done;
  124. end.
  125.