home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / 123demo / demo123.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-15  |  10.1 KB  |  334 lines

  1. {Demo Program to demonstrate how to use unit123.PAS}
  2. {R. G. Minutillo: 7/1/95}
  3. unit demo123;
  4.  
  5. interface
  6.  
  7. uses
  8.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  9.   Forms, Dialogs, unit123, StdCtrls;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     Button1: TButton;
  14.     Edit1: TEdit;
  15.     Edit2: TEdit;
  16.     Edit3: TEdit;
  17.     Edit4: TEdit;
  18.     Button2: TButton;
  19.     Button3: TButton;
  20.     OpenDialog1: TOpenDialog;
  21.     Edit5: TEdit;
  22.     Edit6: TEdit;
  23.     Button4: TButton;
  24.     procedure Button1Click(Sender: TObject);
  25.     procedure Button2Click(Sender: TObject);
  26.     procedure Button3Click(Sender: TObject);
  27.     procedure LotusFormat(a: byte);
  28.     procedure Button4Click(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);
  44. var
  45. i: integer;
  46. s: string;
  47. t: string;
  48. begin
  49.    if not Lotus_end_of_File then begin
  50.         repeat Read_Lotus_Record
  51.          until ((Lotus.Cell_Type<>Blank_Type) and (Lotus.Cell_Type<>Unidentified_Type));
  52.  
  53.         {}
  54.             Case Lotus.Cell_Type of
  55.             End_Of_File_Type:
  56.                  begin
  57.                 Edit1.TEXT:='End of File';
  58.                  EDIT2.TEXT:='';
  59.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  60.                  EDIT4.TEXT:='';
  61.                 end;
  62.             Column_Width_Type:
  63.                 begin
  64.                 EDIT1.TEXT:='Column Width';
  65.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  66.                  EDIT3.TEXT:='';
  67.                  EDIT4.TEXT:='';
  68.                 end;
  69.  
  70.             Range_Type:
  71.                 begin
  72.                 EDIT1.TEXT:='Lotus Range';
  73.                  EDIT2.TEXT:=Lotus.Alpha_Range_Start;
  74.                  EDIT3.TEXT:=Lotus.Alpha_Range_End;
  75.                  EDIT4.TEXT:=Lotus.range_name;
  76.                 end;
  77.  
  78.             PRange_Type:
  79.                 begin
  80.                 EDIT1.TEXT:='Lotus Print Range';
  81.                  EDIT2.TEXT:=Lotus.Alpha_PRange_Start;
  82.                  EDIT3.TEXT:=Lotus.Alpha_PRange_End;
  83.                  EDIT4.TEXT:='';
  84.                 end;
  85.  
  86.             PMargins_Type:
  87.                 begin
  88.                 EDIT1.TEXT:='Lotus Print Margins';
  89.                  EDIT2.TEXT:='Top: '+inttostr(lotus.PMargins_Top)+ ' - Bot: ' + inttostr(lotus.PMargins_Bottom);
  90.                  EDIT2.TEXT:='Left: '+inttostr(lotus.PMargins_Left)+ ' - Right: ' + inttostr(lotus.PMargins_Right);
  91.                  EDIT4.TEXT:='Lines: ' + inttostr(lotus.PMargins_Page_Lines);
  92.                 end;
  93.  
  94.             ARange_Type:
  95.                 begin
  96.                 EDIT1.TEXT:='Lotus Active Range';
  97.                  EDIT2.TEXT:=Lotus.Alpha_ARange_Start;
  98.                  EDIT3.TEXT:=Lotus.Alpha_ARange_End;
  99.                  EDIT4.TEXT:='';
  100.                 end;
  101.  
  102.             Print_Setup_Type:
  103.                 begin
  104.                 EDIT1.TEXT:='Print Setup String';
  105.                  EDIT2.TEXT:=Lotus.Print_Setup_Value;
  106.                  EDIT3.TEXT:='';
  107.                  EDIT4.TEXT:='';
  108.                 end;
  109.  
  110.             Blank_Type:
  111.                 begin
  112.                  EDIT1.TEXT:='Blank Cell';
  113.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  114.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  115.                  EDIT4.TEXT:='';
  116.                  end;
  117.  
  118.             Integer_Type:
  119.                  begin
  120.                  EDIT1.TEXT:='Integer Cell';
  121.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  122.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  123.                  EDIT4.TEXT:=inttostr(Lotus.integer_value);
  124.                 end;
  125.  
  126.             Real_Type:
  127.                  begin
  128.                  EDIT1.TEXT:='Real Number Cell';
  129.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  130.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  131.                  EDIT4.TEXT:=floattostr(lotus.real_value);
  132.              end;
  133.  
  134.             Label_Type:
  135.                 begin
  136.                  EDIT1.TEXT:='Label Cell';
  137.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  138.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  139.                  EDIT4.TEXT:=lotus.label_value;
  140.                  end;
  141.  
  142.             Formula_Type:
  143.                 begin
  144.                  EDIT1.TEXT:='Formula Cell';
  145.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  146.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  147.                  EDIT4.TEXT:=floattostr(lotus.formula_value);
  148.                 end;
  149.  
  150.             Protection_Type:
  151.                 begin
  152.                  EDIT1.TEXT:='Global Protection';
  153.                  if ord(Lotus.Protection_Value)<> 0 then
  154.                    EDIT2.TEXT:='On' else EDIT2.TEXT:='Off';
  155.                  EDIT3.TEXT:='';
  156.                  EDIT4.TEXT:='';
  157.                 end;
  158.  
  159.             Unidentified_Type:
  160.                  begin
  161.                  EDIT1.TEXT:='Unidentified Cell';
  162.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  163.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  164.                  EDIT4.TEXT:='';
  165.                 end;
  166.  
  167.             Else
  168.                  begin
  169.                  EDIT1.TEXT:='Unidentified Cell';
  170.                  EDIT2.TEXT:=Lotus.Alpha_Column;
  171.                  EDIT3.TEXT:='Row:'+inttostr(lotus.Row)+ ' - Col:' + inttostr(lotus.column);
  172.                  EDIT4.TEXT:='';
  173.                 end;
  174.            end;
  175.  
  176.            LotusFormat(Lotus.Format);
  177.     end;
  178. end;
  179.  
  180. procedure TForm1.Button2Click(Sender: TObject);
  181. begin
  182.     if opendialog1.execute then  begin
  183.        Lotus_Read_File_Name:=opendialog1.filename;
  184.        Open_Lotus_Read_File;        {Open a WKS, WK1 file and read version  }
  185.        Edit1.Text:=opendialog1.filename;
  186.        Edit2.Text:=Lotus_Version_Name;
  187.        end;
  188.     end;
  189.  
  190. procedure TForm1.Button3Click(Sender: TObject);
  191. begin
  192. CLose;
  193. end;
  194. procedure Tform1.LotusFormat(a: byte);
  195. begin
  196. if a >=128 then edit5.text:='protected' else edit5.text:='unprotected';
  197. {b:=(a and 112) div 16;}
  198. case (a and 112) div 16 of
  199.      0:          edit5.text:=edit5.text + ' ' + 'fixed';
  200.      1:          edit5.text:=edit5.text + ' ' + 'scientific';
  201.      2:          edit5.text:=edit5.text + ' ' + 'currency';
  202.      3:          edit5.text:=edit5.text + ' ' + 'percent';
  203.      4:          edit5.text:=edit5.text + ' ' + 'comma';
  204.      5:          edit5.text:=edit5.text + ' ' + 'unused';
  205.      6:          edit5.text:=edit5.text + ' ' + 'unused';
  206.      7:          edit5.text:=edit5.text + ' ' + 'special';
  207.      end;
  208.  
  209. if ((a and 112)div 16)< 7 then
  210.      edit5.text:=edit5.text + ' ' + inttostr(a and 15)+' decimal places'
  211. else
  212.      case a and 15 of
  213.      0: edit5.text:=edit5.text + ' ' + '+/-';
  214.      1: edit5.text:=edit5.text + ' ' + 'general';
  215.      2: edit5.text:=edit5.text + ' ' + 'day-month-year';
  216.      3: edit5.text:=edit5.text + ' ' + 'day-month';
  217.      4: edit5.text:=edit5.text + ' ' + 'month-year';
  218.      5: edit5.text:=edit5.text + ' ' + 'text';
  219.      6: edit5.text:=edit5.text + ' ' + 'hidden';
  220.      7: edit5.text:=edit5.text + ' ' + 'date:h:m:s';
  221.      8: edit5.text:=edit5.text + ' ' + 'date:h:m';
  222.      9: edit5.text:=edit5.text + ' ' + 'date: intl';
  223.      10: edit5.text:=edit5.text + ' ' + 'date: intl';
  224.      11: edit5.text:=edit5.text + ' ' + 'time: intl';
  225.      12: edit5.text:=edit5.text + ' ' + 'time: intl';
  226.      13: edit5.text:=edit5.text + ' ' + 'unused';
  227.      14: edit5.text:=edit5.text + ' ' + 'unused';
  228.      15: edit5.text:=edit5.text + ' ' + 'default';
  229.      end;
  230. edit6.text:=inttostr(ord(a));
  231. end;
  232.  
  233. procedure TForm1.Button4Click(Sender: TObject);
  234. var i,j: integer;
  235. d: real;
  236. s: string;
  237. begin
  238. Lotus_Write_File_Name:='123test.wk1';
  239. Open_Lotus_Write_File;
  240.  
  241. Lotus.Row:=0;
  242. Lotus.Column:=0;
  243.  
  244. Lotus.Cell_Type:=Protection_Type;
  245. Lotus.Protection_Value:=1;
  246. Write_Lotus_Record;
  247.  
  248. Lotus.Cell_Type:=Print_Setup_Type;
  249. Lotus.Print_Setup_Value:='\027E\027&l1O\027(0U\027(s0p18.75H';
  250. Write_Lotus_Record;
  251.  
  252. Lotus.Cell_Type:=PRange_Type;
  253. Lotus.PRange_Start_Column:=0;
  254. Lotus.PRange_Start_Row:=0;
  255. Lotus.PRange_End_Column:=4;
  256. Lotus.PRange_End_Row:=14;
  257. Write_Lotus_Record;
  258.  
  259. Lotus.Cell_Type:=ARange_Type;
  260. Lotus.ARange_Start_Column:=0;
  261. Lotus.ARange_Start_Row:=0;
  262. Lotus.ARange_End_Column:=4;
  263. Lotus.ARange_End_Row:=14;
  264. Write_Lotus_Record;
  265.  
  266. Lotus.Cell_Type:=PMargins_type;
  267. Lotus.PMargins_left:=5;
  268. Lotus.PMargins_Right:=70;
  269. Lotus.PMargins_Page_Lines:=60;
  270. Lotus.PMargins_Top:=5;
  271. Lotus.PMargins_Bottom:=5;
  272. Write_Lotus_Record;
  273.  
  274. Lotus.Cell_Type:=Label_Type;
  275. Lotus.Label_Value:='^This is a Lotus Test File!';
  276. Write_Lotus_Record;
  277.  
  278. Lotus.Cell_type:=Column_Width_Type;
  279. Lotus.Column_Width:=16;
  280. Write_Lotus_Record;
  281.  
  282. for i:=1 to 4 do
  283.     for j:=0 to 4 do begin
  284.         Lotus.Row:=i;
  285.         Lotus.Column:=j;
  286.  
  287.         if j>0 then begin
  288.            Lotus.Real_Value:=i * j + 6;
  289.            if i mod 2 = 0 then Lotus.Format:=162 else Lotus.Format:=130;
  290.            Lotus.Cell_Type:=Real_Type;
  291.            end
  292.         else begin
  293.             Lotus.Integer_Value:= i*(2*j)+8;
  294.             if i mod 2 = 0 then Lotus.Format:=192 else Lotus.Format:=150;
  295.             Lotus.Cell_Type:=Integer_Type;
  296.             end;
  297.         Write_Lotus_Record;
  298.         end;
  299.  
  300. Lotus.Cell_Type:=Formula_Type;
  301. Lotus.Row:=14;
  302. Lotus.Column:=1;
  303. Lotus.Format:=255;
  304. Lotus.Formula_Length:=12;
  305.  
  306. {the formula is in reverse polish notation, so read up, sort of}
  307.  
  308. Lotus.Formula[0] := 2;     {The opcode 2 indicates that a cell range follows}
  309.  
  310. Lotus.Formula[1] := 0;     {this sequence is a range, two bytes each}
  311. Lotus.Formula[2] := 128;   {for start row, start col, end row, and}
  312. Lotus.Formula[3] := 244;   {end column. This particular range consists}
  313. Lotus.Formula[4] := 159;   {of all relative addresses. and represents}
  314. Lotus.Formula[5] := 0;     {the range B3..B14, in cell B15.}
  315. Lotus.Formula[6] := 128;   {There's something in the two bytes}
  316. Lotus.Formula[7] := 255;   {for each row or column which must}
  317. Lotus.Formula[8] := 159;   {represent an offset and a relative direction}
  318.  
  319. Lotus.Formula[9] := 80;    {Opcode 80 represents @SUM}
  320. Lotus.Formula[10] := 1;    {Byte for the number of arguments}
  321.  
  322. Lotus.Formula[11] := 3;    {End of Formula indicator, opcode 3}
  323.  
  324.                            {no need for a formula_value, it will}
  325.                            {get updated on the load recalc anyway}
  326. Write_Lotus_Record;
  327.  
  328. Close_Lotus_Write_File;
  329.  
  330. end;
  331.  
  332. end.
  333.  
  334.