home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / unity / d345 / ALP.ZIP / ALPTable.pas < prev   
Pascal/Delphi Source File  |  2001-05-23  |  20KB  |  752 lines

  1. unit ALPTable;
  2. {-----------------------------------------------------------------------------
  3.  Universal table component of access to databases without BDE
  4.  Last modification : 23 May 2001
  5.  (Please write this last modification date in your e-mails.)
  6.  
  7.  Version:     1.17
  8.  Author:    Momot Alexander (Deleon)
  9.  Http:          http://www.dbwork.chat.ru
  10.  E-Mail:    dbwork@chat.ru
  11.  Status:    FreeWare
  12.  Delphi:        32-bit versions
  13.  Platform:    Windows 32-bit versions.
  14.  
  15. -----------------------------------------------------------------------------}
  16. {$R *.DCR}
  17. {$DEFINE REGISTERONPAGE}
  18. interface
  19.  
  20. uses
  21.   Windows,   Messages,   SysUtils,  Classes,
  22.   Forms,     Db,        ALP,        DsgnIntf;
  23.  
  24. type
  25.   PRecInfo = ^TRecInfo;
  26.   TRecInfo = packed record
  27.     RecordNumber: Longint;
  28.     UpdateStatus: TUpdateStatus;
  29.     BookmarkFlag: TBookmarkFlag;
  30.   end;
  31.  
  32.   TALPTable = packed class(TDataSet)
  33.   private
  34.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35.     //FDbHandle     : pEDIDB;
  36.     FHandle       : ALP_HANDLE;
  37.     FRecProps     : RecProps;
  38.     FCurRec       : Integer;
  39.     FExclusive    : boolean;
  40.     FReadOnly     : boolean;
  41.  
  42.     FRecordSize   : Word;
  43.     FBookmarkOfs  : Word;
  44.     FRecInfoOfs   : Word;
  45.     FBlobCacheOfs : Word;
  46.     FRecBufSize   : Word;
  47.  
  48.     FFileName     : string;
  49.     FDatabaseName : string;
  50.     FTableName    : string;
  51.     FLastBookmark : Integer;
  52.     procedure InitBufferPointers(GetProps: Boolean);
  53.     procedure SetExclusive(Value: boolean);
  54.     procedure SetFileName(Value: string);
  55.     function  GetActiveRecBuf(var RecBuf: PChar): Boolean;
  56.     procedure SetTableName(const Value: string);
  57.     procedure SetDatabaseName(const Value: string);
  58.   protected
  59.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60.     function  CreateHandle: ALP_HANDLE;
  61.     procedure DestroyHandle;
  62.     procedure OpenCursor(InfoQuery: Boolean); override;
  63.     procedure CloseCursor; override;
  64.     function  AllocRecordBuffer: PChar; override;
  65.     procedure FreeRecordBuffer(var Buffer: PChar); override;
  66.     procedure GetBookmarkData(Buffer: PChar; Data: Pointer); override;
  67.     function  GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; override;
  68.     function  GetRecord(Buffer: PChar; GetMode: TGetMode; DoCheck: Boolean): TGetResult; override;
  69.     function  GetRecordSize: Word; override;
  70.     procedure AddFieldDesc(pFld: pFLDDesc; FieldDefs: TFieldDefs);
  71.     procedure InitRecord(Buffer: PChar); override;
  72.     procedure InternalAddRecord(Buffer: Pointer; Append: Boolean); override;
  73.     procedure InternalClose; override;
  74.     procedure InternalDelete; override;
  75.     procedure InternalFirst; override;
  76.     procedure InternalGotoBookmark(Bookmark: Pointer); override;
  77.     procedure InternalHandleException; override;
  78.     procedure InitFieldDefs; override;
  79.     procedure InternalInitFieldDefs; override;
  80.     procedure InternalInitRecord(Buffer: PChar); override;
  81.     procedure InternalInsert; override;
  82.     procedure InternalLast; override;
  83.     procedure InternalOpen; override;
  84.     procedure InternalPost; override;
  85.     procedure InternalSetToRecord(Buffer: PChar); override;
  86.     function  IsCursorOpen: Boolean; override;
  87.     procedure SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag); override;
  88.     procedure SetBookmarkData(Buffer: PChar; Data: Pointer); override;
  89.     procedure SetFieldData(Field: TField; Buffer: Pointer); override;
  90.     function  GetRecordCount: Integer; override;
  91.     function  GetRecNo: Integer; override;
  92.     procedure SetRecNo(Value: Integer); override;
  93.   public
  94.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95.     function  GetFieldData(Field: TField; Buffer: Pointer): Boolean; override;
  96.     procedure CreateTable;
  97.     property  Handle : ALP_HANDLE read FHandle;
  98.   published
  99.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100.     property Active;
  101.     property AutoCalcFields;
  102.     property DatabaseName: string read FDatabaseName write SetDatabaseName;
  103.     property Exclusive: boolean read FExclusive write SetExclusive;
  104.     property Filter;
  105.     property Filtered;
  106.     property FilterOptions;
  107.     property TableName: string read FTableName write SetTableName;
  108.     property ReadOnly: boolean read FReadOnly write FReadOnly;
  109.     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110.     property ObjectView default False;
  111.     property BeforeOpen;
  112.     property AfterOpen;
  113.     property BeforeClose;
  114.     property AfterClose;
  115.     property BeforeInsert;
  116.     property AfterInsert;
  117.     property BeforeEdit;
  118.     property AfterEdit;
  119.     property BeforePost;
  120.     property AfterPost;
  121.     property BeforeCancel;
  122.     property AfterCancel;
  123.     property BeforeDelete;
  124.     property AfterDelete;
  125.     property BeforeScroll;
  126.     property AfterScroll;
  127.     property BeforeRefresh;
  128.     property AfterRefresh;
  129.     property OnCalcFields;
  130.     property OnDeleteError;
  131.     property OnEditError;
  132.     property OnNewRecord;
  133.     property OnPostError;
  134.   end;
  135.  
  136.   TALPException = class(Exception);
  137.  
  138. procedure Check(Status: ALPResult);
  139. procedure Register;
  140.  
  141. implementation
  142.  
  143. procedure Check(Status: ALPResult);
  144. begin
  145.  case( Status )of
  146.  ERR_UNSUPPORTEDFILE  : raise TALPException.Create('Unsupported file format');
  147.  ERR_CANNOTOPENFILE   : raise TALPException.Create('Cannot open file');
  148.  ERR_CANNOTCLOSEFILE  : raise TALPException.Create('Cannot close file');
  149.  ERR_INVALIDFILE      : raise TALPException.Create('Invalid file');
  150.  ERR_INVALIDHANDLE    : raise TALPException.Create('Invalid handle');
  151.  ERR_INVALIDFILENAME  : raise TALPException.Create('Invalid file name');
  152.  ERR_FILENOTEXIST     : raise TALPException.Create('File not found');
  153.  ERR_CANNOTSEEK       : raise TALPException.Create('Cannot seek');
  154.  ERR_CANNOTREADFILE   : raise TALPException.Create('Cannot read file');
  155.  ERR_CANNOTWRITEFILE  : raise TALPException.Create('Cannot write file');
  156.  ERR_BOF              : raise TALPException.Create('At the begin of file');
  157.  ERR_EOF              : raise TALPException.Create('At the end of file');
  158.  ERR_BUFFERISEMPTY    : raise TALPException.Create('Buffer is empty');
  159.  ERR_INVALIDFIELDDESC : raise TALPException.Create('Invalid field descriptor');
  160.  ERR_INVALIDINDEXDESC : raise TALPException.Create('Invalid index descriptor');
  161.  ERR_RECDELETED       : raise TALPException.Create('Record deleted');
  162.  end;{ case }
  163. end;
  164.  
  165. function _IsDirectory(const DatabaseName: string): Boolean;
  166. var
  167.   I: Integer;
  168. begin
  169.   Result := True;
  170.   if (DatabaseName = '') then Exit;
  171.   I := 1;
  172.   while I <= Length(DatabaseName) do
  173.   begin
  174.     if DatabaseName[I] in [':','\'] then Exit;
  175.     if DatabaseName[I] in LeadBytes then Inc(I, 2)
  176.     else Inc(I);
  177.   end;
  178.   Result := False;
  179. end;
  180.  
  181. function _NormalDir(const DirName: string): string;
  182. begin
  183.   Result := DirName;
  184.   if (Result <> '') and
  185.     not (Result[Length(Result)] in [':', '\']) then
  186.   begin
  187.     if (Length(Result) = 1) and (UpCase(Result[1]) in ['A'..'Z']) then
  188.       Result := Result + ':\'
  189.     else Result := Result + '\';
  190.   end;
  191. end;
  192.  
  193. procedure TALPTable.InternalOpen;
  194. begin
  195.  FRecordSize  := FHandle^.iDataSize;
  196.  BookmarkSize := SizeOf(IBOOKMARK);
  197.  FieldDefs.Updated := False;
  198.  FieldDefs.Update;
  199.  if DefaultFields then CreateFields;
  200.  BindFields(True);
  201.  InitBufferPointers(False);
  202.  ALPSetToBegin(FHandle);
  203. end;
  204.  
  205. procedure TALPTable.InternalClose;
  206. begin
  207.  BindFields(False);
  208.  if DefaultFields then DestroyFields;
  209. end;
  210.  
  211. function TALPTable.IsCursorOpen: Boolean;
  212. begin
  213.   Result := Assigned( FHandle );
  214. end;
  215.  
  216. procedure TALPTable.InternalInitFieldDefs;
  217. var
  218.   I          : Integer;
  219.   pFLD       : pFLDDesc;
  220. begin
  221.   FieldDefs.Clear;
  222.   pFLD := FHandle^.pFIELDS;
  223.   for I := 1 to FHandle^.iNumFlds do
  224.   begin
  225.    AddFieldDesc(pFLD, FieldDefs);
  226.    inc(pFLD);
  227.   end;{ while }
  228. end;
  229.  
  230. { Field Related }
  231.  
  232. procedure TALPTable.AddFieldDesc(pFld: pFLDDesc; FieldDefs: TFieldDefs);
  233. var
  234.   FType: TFieldType;
  235.   FSize: Word;
  236.   FRequired: Boolean;
  237.   FPrecision, I: Integer;
  238.   FName: string;
  239. begin
  240.   with( pFLD^ )do
  241.   begin
  242.     I := 0;
  243.     FName := szName;
  244.     while FieldDefs.IndexOf(FName) >= 0 do
  245.     begin
  246.       Inc(I);
  247.       FName := Format('%s_%d', [szName, I]);
  248.     end;
  249.     //------------------------------
  250.     FType     := TFieldType(iFldType);
  251.     FRequired := False;
  252.     //------------------------------
  253.     case( ALP_FLDTYPE(iFldType) )of
  254.     uftString, uftBytes, uftVarBytes,
  255.     uftADT, uftArray, uftReference:
  256.         begin
  257.          FSize := iFldSize;
  258.         end;
  259.     uftBCD:
  260.         begin
  261.          FSize      := iFldSig;
  262.          FPrecision := iFldDec;
  263.         end;
  264.     uftBLOB:
  265.         begin
  266.          FSize := iFldSize;
  267.         end;
  268.     else
  269.      FSize      := 0;
  270.      FPrecision := 0;
  271.     end;{ case }
  272.     //------------------------------
  273.     with FieldDefs.AddFieldDef do
  274.     begin
  275.      FieldNo   := pFLD^.iFldNum + 1;
  276.      Name      := FName;
  277.      DataType  := FType;
  278.      Size      := FSize;
  279.      Precision := FPrecision;
  280.      if( FRequired )then Attributes := [faRequired];
  281.      if( DataType = ftAutoInc )then
  282.       Attributes := Attributes + [faReadonly];
  283.     end;{ with }
  284.   end;{ with }
  285. end;
  286.  
  287. procedure TALPTable.InternalHandleException;
  288. begin
  289.   Application.HandleException(Self);
  290. end;
  291.  
  292. procedure TALPTable.InternalGotoBookmark(Bookmark: Pointer);
  293. begin
  294.   Check(ALPSetToBookmark(FHandle, Bookmark));
  295. end;
  296.  
  297. procedure TALPTable.InternalSetToRecord(Buffer: PChar);
  298. begin
  299.   InternalGotoBookmark(Buffer + FBookmarkOfs);
  300. end;
  301.  
  302. function TALPTable.GetBookmarkFlag(Buffer: PChar): TBookmarkFlag;
  303. begin
  304.   Result := PRecInfo(Buffer + FRecInfoOfs)^.BookmarkFlag;
  305. end;
  306.  
  307. procedure TALPTable.SetBookmarkFlag(Buffer: PChar; Value: TBookmarkFlag);
  308. begin
  309.   PRecInfo(Buffer + FRecInfoOfs)^.BookmarkFlag := Value;
  310. end;
  311.  
  312. procedure TALPTable.GetBookmarkData(Buffer: PChar; Data: Pointer);
  313. begin
  314.   Move(Buffer[FBookmarkOfs], Data^, BookmarkSize);
  315. end;
  316.  
  317. procedure TALPTable.SetBookmarkData(Buffer: PChar; Data: Pointer);
  318. begin
  319.   Move(Data^, Buffer[FBookmarkOfs], BookmarkSize);
  320. end;
  321.  
  322. function TALPTable.GetRecordSize: Word;
  323. begin
  324.  Result := FHandle^.iDataSize;
  325. end;
  326.  
  327. function TALPTable.AllocRecordBuffer: PChar;
  328. begin
  329.  Result := AllocMem(FRecBufSize);
  330. end;
  331.  
  332. procedure TALPTable.FreeRecordBuffer(var Buffer: PChar);
  333. begin
  334.   FreeMem(Buffer, FRecBufSize);
  335. end;
  336.  
  337. function TALPTable.GetRecord(Buffer: PChar; GetMode: TGetMode;
  338.   DoCheck: Boolean): TGetResult;
  339. var
  340.   Status: ALPResult;
  341. begin
  342.   case( GetMode )of
  343.     gmCurrent:
  344.       Status := ALPGetRecord(FHandle, Buffer, @FrecProps);
  345.     gmNext:
  346.       Status := ALPGetNextRecord(FHandle, Buffer, @FrecProps);
  347.     gmPrior:
  348.       Status := ALPGetPriorRecord(FHandle, Buffer, @FrecProps);
  349.   else
  350.     Status := ERR_NONE;
  351.   end;
  352.   //------------
  353.   case( Status )of
  354.   ERR_NONE:
  355.     begin
  356.      with pRecInfo(Buffer + FRecInfoOfs)^ do
  357.      begin
  358.       UpdateStatus := usUnmodified;
  359.       BookmarkFlag := bfCurrent;
  360.       RecordNumber := FRecProps.iRecNum;
  361.       Check(ALPGetBookmark(FHandle, Buffer + FBookmarkOfs));
  362.       Result := grOK;
  363.      end;{ with }
  364.     end;
  365.   ERR_BOF: Result := grBOF;
  366.   ERR_EOF: Result := grEOF;
  367.   else
  368.   Result := grError;
  369.   if DoCheck then Check(Status);
  370.   end;{ case }
  371. end;
  372.  
  373. procedure TALPTable.InternalInitRecord(Buffer: PChar);
  374. begin
  375.   ALPInitRecord(FHandle, Buffer);
  376. end;
  377.  
  378. procedure TALPTable.SetFieldData(Field: TField; Buffer: Pointer);
  379. var
  380.   RecBuf: PChar;
  381. begin
  382.   with Field do
  383.   begin
  384.    GetActiveRecBuf(RecBuf);
  385.    if( FieldNo > 0 )then
  386.    begin
  387.     Validate(Buffer);
  388.     if FieldKind <> fkInternalCalc then
  389.     begin
  390.      Check(ALPPutField(FHandle, FieldNo, RecBuf, Buffer));
  391.     end;
  392.    end else {fkCalculated, fkLookup}
  393.    begin
  394.     Inc(RecBuf, FRecordSize + Offset);
  395.     Boolean(RecBuf[0]) := LongBool(Buffer);
  396.     if Boolean(RecBuf[0]) then Move(Buffer^, RecBuf[1], DataSize);
  397.    end;
  398.    if not (State in [dsCalcFields, dsFilter, dsNewValue]) then
  399.     DataEvent(deFieldChange, Longint(Field));
  400.   end;
  401. end;
  402.  
  403. procedure TALPTable.InternalFirst;
  404. begin
  405.  ALPSetToBegin(FHandle);
  406. end;
  407.  
  408. procedure TALPTable.InternalLast;
  409. begin
  410.  ALPSetToEnd(FHandle);
  411. end;
  412.  
  413. procedure TALPTable.InternalPost;
  414. begin
  415.   if State = dsEdit then
  416.     Check(ALPModifyRecord(FHandle, ActiveBuffer, True)) else
  417.     Check(ALPInsertRecord(FHandle, ActiveBuffer));
  418. end;
  419.  
  420. procedure TALPTable.InternalAddRecord(Buffer: Pointer; Append: Boolean);
  421. begin
  422.   if Append then
  423.     Check(ALPAppendRecord(FHandle, Buffer)) else
  424.     Check(ALPInsertRecord(FHandle, Buffer));
  425. end;
  426.  
  427. procedure TALPTable.InternalDelete;
  428. begin
  429.   Check( ALPDeleteRecord(FHandle, nil));
  430. end;
  431.  
  432. function TALPTable.GetRecordCount: Longint;
  433. begin
  434.   CheckActive;
  435.   if (ALPGetRecordCount(FHandle, Result) <> ERR_NONE) then
  436.     Result := -1;
  437. end;
  438.  
  439. function TALPTable.GetRecNo: Longint;
  440. var
  441.   BufPtr: PChar;
  442. begin
  443.   CheckActive;
  444.   if State = dsCalcFields then
  445.     BufPtr := CalcBuffer else
  446.     BufPtr := ActiveBuffer;
  447.   Result := PRecInfo(BufPtr + FRecInfoOfs).RecordNumber;
  448. end;
  449.  
  450. procedure TALPTable.SetRecNo(Value: Integer);
  451. begin
  452.  {
  453.   if (Value >= 0) and (Value < FData.Count) then
  454.   begin
  455.     FCurRec := Value - 1;
  456.     Resync([]);
  457.   end;
  458.  }
  459. end;
  460.  
  461. function TALPTable.CreateHandle: ALP_HANDLE;
  462. begin
  463.  FHandle := nil;
  464.  if _IsDirectory( FDatabaseName )then
  465.  FFileName  := _NormalDir( FDatabaseName ) + FTableName;
  466.  
  467.  Check(
  468.  ALPOpenTable(
  469.               FFileName,
  470.               FReadOnly,
  471.               FExclusive,
  472.               FHandle
  473.              )
  474.        );
  475.  Result := FHandle;
  476. end;
  477.  
  478. procedure TALPTable.DestroyHandle;
  479. begin
  480.  ALPCloseTable(FHandle);
  481. end;
  482.  
  483. procedure TALPTable.CloseCursor;
  484. begin
  485.   inherited CloseCursor;
  486.   if FHandle <> nil then
  487.   begin
  488.    DestroyHandle;
  489.    FHandle := nil;
  490.   end;
  491. end;
  492.  
  493. procedure TALPTable.InitFieldDefs;
  494. var
  495.   I        : Integer;
  496.   pFld     : pFLDDESC;
  497.   hHandle  : ALP_HANDLE;
  498.   Result   : ALPRESULT;
  499.   FldCount : Integer;
  500. begin
  501.   hHandle := nil;
  502.   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  503.   if _IsDirectory( FDatabaseName )then
  504.   FFileName  := _NormalDir( FDatabaseName ) + FTableName;
  505.   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  506.   Result := ALPOpenTable(FFileName, True, False, hHandle);
  507.   if( Result = ERR_NONE )then
  508.   begin
  509.    pFLD     := hHandle^.pFIELDS;
  510.    FldCount := hHandle^.iNumFlds;
  511.  
  512.    FieldDefs.BeginUpdate;
  513.    try
  514.     FieldDefs.Clear;
  515.     for I := 1 to FldCount do
  516.     begin
  517.      AddFieldDesc(pFLD, FieldDefs);
  518.      inc(pFLD);
  519.     end;{ for }
  520.    finally
  521.     FieldDefs.EndUpdate;
  522.    end;{ fin }
  523.    ALPCloseTable(hHandle);
  524.   end;{ if }
  525. end;
  526.  
  527. procedure TALPTable.OpenCursor(InfoQuery: Boolean);
  528. begin
  529.   if( FHandle = nil )then
  530.     FHandle := CreateHandle;
  531.   inherited OpenCursor(InfoQuery);
  532. end;
  533.  
  534. procedure TALPTable.InitBufferPointers(GetProps: Boolean);
  535. begin
  536.   if GetProps then
  537.   begin
  538.    BookmarkSize := SizeOf(IBookmark);
  539.    FRecordSize  := FHandle^.iDataSize;
  540.   end;
  541.   FBlobCacheOfs := FRecordSize + CalcFieldsSize;
  542.   FRecInfoOfs   := FBlobCacheOfs + BlobFieldCount * SizeOf(Pointer);
  543.   FBookmarkOfs  := FRecInfoOfs + SizeOf(TRecInfo);
  544.   FRecBufSize   := FBookmarkOfs + BookmarkSize;
  545. end;
  546.  
  547. procedure TALPTable.CreateTable;
  548. var
  549.  TblDesc: ICRTblDesc;
  550.  Handle : ALP_HANDLE;
  551.  
  552.  procedure InitTableSettings;
  553.  begin
  554.   FillChar(TblDesc, SizeOf(TblDesc), 0);
  555.   StrPCopy(TblDesc.szDbName, FDatabaseName);
  556.   StrPCopy(TblDesc.szTblName, FTableName);
  557.   TblDesc.iTblType := ttEJM;
  558.  end;{ proc }
  559.  
  560.  procedure InitFieldDescriptors;
  561.  var
  562.   I    : Integer;
  563.   pPos : pFLDDESC;
  564.  begin
  565.   InitFieldDefsFromFields;
  566.   TblDesc.iFldCount := FieldDefs.Count;
  567.   TblDesc.pFldDesc  := AllocMem(SizeOf(FldDesc) * TblDesc.iFldCount);
  568.   pPos := TblDesc.pFldDesc;
  569.   for I := 0 to FieldDefs.Count - 1 do
  570.   with FieldDefs[I] do
  571.   begin
  572.    pPos^.iFldNum  := I;
  573.    StrPCopy(pPos^.szName, Name);
  574.    pPos^.iFldType := ALP_FLDTYPE(DataType);
  575.    pPos^.iFldSize := Size;
  576.    inc( pPos );
  577.   end;{ with - for }
  578.  end;{ proc }
  579.  
  580. begin
  581.   CheckInactive;
  582.   InitTableSettings;
  583.   InitFieldDescriptors;
  584.   //InitIndexDescriptors;
  585.   ALPTableCreate(@TblDesc, False, Handle);
  586. end;
  587.  
  588. procedure TALPTable.SetExclusive(Value: boolean);
  589. begin
  590.  CheckInactive;
  591.  FExclusive := Value;
  592. end;
  593.  
  594. procedure TALPTable.SetFileName(Value: string);
  595. begin
  596.  CheckInactive;
  597.  FFileName := Value;
  598. end;
  599.  
  600. function TALPTable.GetActiveRecBuf(var RecBuf: PChar): Boolean;
  601. begin
  602.   case State of
  603.     //dsBlockRead: RecBuf := FBlockReadBuf + (FBlockBufOfs * FRecordSize);
  604.     dsBrowse: if IsEmpty then RecBuf := nil else RecBuf := ActiveBuffer;
  605.     dsEdit, dsInsert: RecBuf := ActiveBuffer;
  606.     //dsSetKey: RecBuf := PChar(FKeyBuffer) + SizeOf(TKeyBuffer);
  607.     dsCalcFields: RecBuf := CalcBuffer;
  608.     //dsFilter: RecBuf := FFilterBuffer;
  609.   else
  610.     RecBuf := nil;
  611.   end;
  612.   Result := RecBuf <> nil;
  613. end;
  614.  
  615. function TALPTable.GetFieldData(Field: TField; Buffer: Pointer): Boolean;
  616. var
  617.   IsBlank: Boolean;
  618.   RecBuf : PChar;
  619. begin
  620.   Result := GetActiveRecBuf(RecBuf);
  621.   if( Result )then
  622.   begin
  623.    Check(ALPGetField(FHandle, Field.FieldNo, RecBuf, Buffer, IsBlank));
  624.    Result := not IsBlank;
  625.   end;
  626. end;
  627.  
  628. procedure TALPTable.InternalInsert;
  629. begin
  630. //  FHandle^.bCUR := True;
  631.   CursorPosChanged;
  632. end;
  633.  
  634. procedure TALPTable.InitRecord(Buffer: PChar);
  635. begin
  636.   inherited InitRecord(Buffer);
  637.   with PRecInfo(Buffer + FRecInfoOfs)^ do
  638.   begin
  639.     UpdateStatus := TUpdateStatus(usInserted);
  640.     BookMarkFlag := bfInserted;
  641.     RecordNumber := -1;
  642.   end;
  643. end;
  644.  
  645. procedure TALPTable.SetTableName(const Value: string);
  646. begin
  647.  CheckInactive;
  648.  FTableName := Value;
  649.  DataEvent(dePropertyChange, 0);
  650. end;
  651.  
  652. procedure TALPTable.SetDatabaseName(const Value: string);
  653. begin
  654.  CheckInactive;
  655.  FDatabaseName := Value;
  656. end;
  657.  
  658.  
  659. {-----------------------------------------------------------------------}
  660. {     Register Properties                                               }
  661. {-----------------------------------------------------------------------}
  662.  
  663. { TDatabaseNameProperty }
  664.  
  665. type
  666.   TDatabaseNameProperty = class(TStringProperty)
  667.   public
  668.     procedure GetValues(Proc: TGetStrProc); override;
  669.     function  GetAttributes: TPropertyAttributes; override;
  670.   end;
  671.  
  672. procedure TDatabaseNameProperty.GetValues(Proc: TGetStrProc);
  673. var
  674.  I: Integer;
  675.  _List: TStringList;
  676. begin
  677.  _List := TStringList.Create;
  678.  try
  679.  {
  680.   SESSION.GetAliasNames(_List);
  681.   for I := 0 to _List.Count - 1 do
  682.   Proc(_List[I]);
  683.   }
  684.  finally
  685.  _List.Free;
  686.  end;
  687. end;
  688.  
  689. function TDatabaseNameProperty.GetAttributes: TPropertyAttributes;
  690. begin
  691.   Result := [paValueList];
  692. end;
  693.  
  694.  
  695. { TTableNameProperty }
  696.  
  697. type
  698.   TTableNameProperty = class(TStringProperty)
  699.   public
  700.     procedure GetValues(Proc: TGetStrProc); override;
  701.     function  GetAttributes: TPropertyAttributes; override;
  702.   end;
  703.  
  704. procedure TTableNameProperty.GetValues(Proc: TGetStrProc);
  705. var
  706.  I      : Integer;
  707.  List   : TStringList;
  708.  FlExt  : string;
  709.  DbName : string;
  710.  Found  : Integer;
  711.  SRec   : TSearchRec;
  712. begin
  713.  List   := TStringList.Create;
  714.  DbName := TALPTable(GetComponent(0)).FDatabaseName;
  715.  if _IsDirectory( DbName )then
  716.  DbName := _NormalDir( DbName );
  717.  try
  718.   Found := FindFirst(DbName + '*.*', faAnyFile, SRec);
  719.   while( Found = 0 )do
  720.   begin
  721.    FlExt := UpperCase(ExtractFileExt(SRec.Name));
  722.    if( SRec.Name <> '.' )and( SRec.Attr and faDirectory = 0 )then
  723.    if( FlExt = '.DB' )or( FlExt = '.DBF' )or
  724.      ( FlExt = '.DAT' )or( FlExt = '.EJM' )then
  725.    List.Add(SRec.Name);
  726.    Found := FindNext( SRec );
  727.   end;{ while }
  728.   FindClose( SRec );
  729.  
  730.   for I := 0 to List.Count - 1 do
  731.   Proc(List[I]);
  732.  finally
  733.   List.Free;
  734.  end;
  735. end;
  736.  
  737. function TTableNameProperty.GetAttributes: TPropertyAttributes;
  738. begin
  739.   Result := [paValueList];
  740. end;
  741.  
  742. procedure Register;
  743. begin
  744.   RegisterPropertyEditor(TypeInfo(string), TALPTable, 'DatabaseName', TDatabaseNameProperty);
  745.   RegisterPropertyEditor(TypeInfo(string), TALPTable, 'TableName', TTableNameProperty);
  746. {$IFDEF REGISTERONPAGE}
  747.   RegisterComponents('Deleon', [TALPTable]);
  748. {$ENDIF}
  749. end;
  750.  
  751. end.
  752.