home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / Tools / Developers / PEDELF32.ZIP / pedelf32 / LOGON.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-09-30  |  3.5 KB  |  118 lines

  1. unit Logon;
  2.                 
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons;
  8.  
  9. type
  10.   TLogOnForm = class(TForm)
  11.     EdtDSN: TEdit;
  12.     EdtUID: TEdit;
  13.     EdtPWD: TEdit;
  14.     EdtDSQ: TEdit;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Label3: TLabel;
  18.     Label4: TLabel;
  19.     BtnLogOnOK: TBitBtn;
  20.     BtnSetLocation: TBitBtn;
  21.     procedure BtnSetLocationClick(Sender: TObject);
  22.     procedure FormShow(Sender: TObject);
  23.     procedure BtnLogOnOKClick(Sender: TObject);
  24.     function GetError(Const JobIn : Integer) : String;
  25.   private
  26.     { Private declarations }
  27.   public
  28.     { Public declarations }
  29.   end;
  30.  
  31. var
  32.   LogOnForm: TLogOnForm;
  33.   Tables : Integer;  {Temporary Variable for number of tables}
  34.  
  35. implementation
  36.    uses Main, CRDelphi;
  37. {$R *.DFM}
  38.  
  39. function TLogOnForm.GetError(Const JobIn : Integer) : String;
  40. {This is my print engine error message capture function. It accepts
  41.  the job number as it parameter and then gets the error code and
  42.  message text and then passes this back out as a formatted string}
  43. var
  44.   Code : SmallInt;
  45.   StrHandle : hWnd;
  46.   Buffer : PChar;
  47.   Length : SmallInt;
  48.   Ret : Bool;
  49.  
  50. begin
  51.    Code := PEGetErrorCode(JobIn); {Get the Error code from the Crpe}
  52.    Ret := PEGetErrorText(JobIn, StrHandle, Length);  {Get the error message handle}
  53.  
  54.    Buffer := StrAlloc(Length);
  55.    {get the text from the text handle}
  56.    Ret := PEGetHandleString(StrHandle, Buffer, Length);
  57.  
  58.    GetError := IntToStr(Code) + ' - ' + StrPas(Buffer); {output the string}
  59.    StrDispose(Buffer);
  60. end;
  61.  
  62. procedure TLogOnForm.BtnSetLocationClick(Sender: TObject);
  63.  
  64. var
  65.    Iterator : Integer;
  66.  
  67. begin
  68.    {Populate the LogInInfo Structure}
  69.    StrPCopy(LogInInfo.ServerName, EdtDSN.Text);
  70.    StrPCopy(LogInInfo.UserID, EdtUID.Text);
  71.    StrPCopy(LogInInfo.Password, EdtPWD.Text);
  72.    StrPCopy(LogInInfo.DatabaseName, EdtDSQ.Text);
  73.  
  74.    If SenderIsLogon then   {if LogonServer menu option was chosen}
  75.       begin
  76.          if PELogonServer('PDSODBC.DLL', LogInInfo)= False then
  77.             ShowMessage(GetError(JobNumber)) {show any error messages}
  78.       end
  79.    else                   {if Logon Info menu option was chosen}
  80.       For Iterator := 0 to (Tables - 1) do
  81.             if PESetNthTableLogOnInfo(JobNumber, Iterator, LogInInfo, True) = False then
  82.                ShowMessage(GetError(JobNumber)); {show any error messages}
  83.  
  84. end;
  85.  
  86. procedure TLogOnForm.FormShow(Sender: TObject);
  87.  
  88. begin
  89.    LogInInfo.StructSize := PE_SIZEOF_LOGON_INFO; {Set Structure size to default}
  90.    If not SenderIsLogOn then   {If Logon Info menu option is chosen}
  91.       begin
  92.          BtnSetLocation.Caption := 'Set Logon Info';
  93.          Tables := PEGetNTables(JobNumber); {get the number of tables in the report}
  94.          {get the log on information for the first table listed in the report}
  95.          if PEGetNthTableLogOnInfo(JobNumber, 0, LogInInfo) then
  96.             begin
  97.                {display the results}
  98.                EdtDSN.Text := LogInInfo.ServerName;
  99.                EdtUID.Text := LogInInfo.UserID;
  100.                EdtPWD.Text := LogInInfo.Password;
  101.                EdtDSQ.Text := LogInInfo.DatabaseName;
  102.             end
  103.          else
  104.              ShowMessage(GetError(JobNumber)); {show any error messages}
  105.       end
  106.    else
  107.        BtnSetLocation.Caption := 'Log On Server';
  108.  
  109. end;
  110.  
  111. procedure TLogOnForm.BtnLogOnOKClick(Sender: TObject);
  112.  
  113. begin
  114.    SenderIsLogon := False;  {Reset the Sender value}
  115. end;
  116.  
  117. end.
  118.