Q&A

  • 3.0에서 5.0으로 업그레이드시 bde관련..소스좀 봐주세요..
EncodeFieldDesc(PFieldDescList(FieldDescs)^[I], Name,          DataType, Size);
하는 부분에서 에러가 발생합니다..
PFieldDescList 를 찾지 못하거든요...
기존 delphi 3.0의 bde에서 5.0으로 업해서 컴파일 하면 나옵니다..
아래에 소스를 첨부하였습니다...
아시는분 계시면 답변 부탁드릴게요...^^



//*****************************************************************
// 소스
//*****************************************************************

unit LDTable;



interface



uses

  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,

  Forms, Dialogs, DB, DBTables, BDE;//DBIProcs, DBITypes, DBIErrs;



type

  TLDTable = class(TTable)

  private

    { Private-Deklarationen }

    FLangDriver: string;

    procedure SetLangDriver(Value: string); {ld special}

    procedure EncodeFieldDesc(var FieldDesc: FLDDesc;

      const Name: string; DataType: TFieldType; Size: Word);

    procedure EncodeIndexDesc(var IndexDesc: IDXDesc;

      const Name, Fields: string; Options: TIndexOptions);

    function GetDriverTypeName(Buffer: PChar): PChar;

    function GetTableTypeName: PChar;

    function IsDBaseTable: Boolean;

  protected

    { Protected-Deklarationen }

  public

    { Public-Deklarationen }

    procedure CreateLDTable;

  published

    { Published-Deklarationen }

    property LangDriver: string read FLangDriver write SetLangDriver;

  end;



procedure Register;



implementation





procedure TLDTable.SetLangDriver(Value: string);

begin

  if FLangDriver <> Value then

    FLangDriver := Value;

end;



procedure TLDTable.CreateLDTable;

var

  I, J: Integer;

  FieldDescs: PFLDDesc;

  ValCheckPtr: PVCHKDesc;

  DriverTypeName: DBINAME;

  TableDesc: CRTblDesc;

  OptFldDesc: pFLDDesc;  {ld special}

  LangDriverName: DBIName; {ld special}

begin

  OptFldDesc := nil; {ld special}

  CheckInactive;

  if FieldDefs.Count = 0 then

    for I := 0 to FieldCount - 1 do

      with Fields[I] do

        if not Calculated then

          FieldDefs.Add(FieldName, DataType, Size, Required);

  FieldDescs := nil;

  FillChar(TableDesc, SizeOf(TableDesc), 0);

  with TableDesc do

  begin

    SetDBFlag(dbfTable, True);

    try

      AnsiToNative(Locale, TableName, szTblName, SizeOf(szTblName) - 1);

      if GetTableTypeName <> nil then

        StrCopy(szTblType, GetTableTypeName);

      iFldCount := FieldDefs.Count;

      FieldDescs := AllocMem(iFldCount * SizeOf(FLDDesc));

      for I := 0 to FieldDefs.Count - 1 do

        with FieldDefs[I] do

        begin
//****************************************************************
// 이부분에서 에러 발생 : PFieldDescList를 인식을 못해요..
//***************************************************************
          EncodeFieldDesc(PFieldDescList(FieldDescs)^[I], Name,

            DataType, Size);
//*****************************************************************

          if Required then Inc(iValChkCount);

        end;

      pFldDesc := AllocMem(iFldCount * SizeOf(FLDDesc));

      Check(DbiTranslateRecordStructure(nil, iFldCount, FieldDescs,

        GetDriverTypeName(DriverTypeName), nil, pFLDDesc));

      iIdxCount := IndexDefs.Count;

      pIdxDesc := AllocMem(iIdxCount * SizeOf(IDXDesc));

      for I := 0 to IndexDefs.Count - 1 do

        with IndexDefs[I] do

          EncodeIndexDesc(PIndexDescList(pIdxDesc)^[I], Name, Fields,

            Options);

      if iValChkCount <> 0 then

      begin

        pVChkDesc := AllocMem(iValChkCount * SizeOf(VCHKDesc));

        ValCheckPtr := pVChkDesc;

        for I := 0 to FieldDefs.Count - 1 do

          if FieldDefs[I].Required then

          begin

            ValCheckPtr^.iFldNum := I + 1;

            ValCheckPtr^.bRequired := True;

            Inc(ValCheckPtr);

          end;

      end;

      if FLangDriver <> '' then       {ld special begin}

      begin

        OptFldDesc := AllocMem(sizeOf(FLDDesc));

        FillChar(OptFldDesc^, sizeOf(FLDDesc),0);

        StrPCopy(OptFldDesc^.szName,'LANGDRIVER');

        OptFldDesc^.iLen := length(FLangDriver)+1;

        AnsiToNative(Locale, FLangDriver, LangDriverName, pred(DBIMaxNameLen));

        iOptParams := 1;

        pFldOptParams := OptFldDesc;

        pOptData := @LangDriverName;

      end;                            {ld special end}

      Check(DbiCreateTable(DBHandle, True, TableDesc));

    finally

      if pVChkDesc <> nil then FreeMem(pVChkDesc, iValChkCount * SizeOf(VCHKDesc));

      if pIdxDesc <> nil then FreeMem(pIdxDesc, iIdxCount * SizeOf(IDXDesc));

      if pFldDesc <> nil then FreeMem(pFldDesc, iFldCount * SizeOf(FLDDesc));

      if FieldDescs <> nil then FreeMem(FieldDescs, iFldCount * SizeOf(FLDDesc));

      if OptFldDesc <> nil then FreeMem(OptFldDesc,SizeOf(FLDDesc)); {ld special}

      SetDBFlag(dbfTable, False);

    end;

  end;

end;



function TLDTable.GetDriverTypeName(Buffer: PChar): PChar;

var

  Length: Word;

begin

  Result := Buffer;

  Check(DbiGetProp(HDBIOBJ(DBHandle), dbDATABASETYPE, Buffer,

    SizeOf(DBINAME), Length));

  if StrIComp(Buffer, 'STANDARD') = 0 then

  begin

    Result := GetTableTypeName;

    if Result <> nil then Result := StrCopy(Buffer, Result);

  end;

end;



function TLDTable.GetTableTypeName: PChar;

const

  Names: array[TTableType] of PChar =

    ('PARADOX', 'PARADOX', 'DBASE', 'ASCIIDRV');

begin

  Result := nil;

  if not Database.IsSQLBased and ((TableType <> ttDefault) or

    (ExtractFileExt(TableName) = '')) then

    Result := Names[TableType];

end;



procedure TLDTable.EncodeFieldDesc(var FieldDesc: FLDDesc;

  const Name: string; DataType: TFieldType; Size: Word);

const

  TypeMap: array[TFieldType] of Byte = (

    fldUNKNOWN, fldZSTRING, fldINT16, fldINT32, fldUINT16, fldBOOL,

    fldFLOAT, fldFLOAT, fldBCD, fldDATE, fldTIME, fldTIMESTAMP, fldBYTES,

    fldVARBYTES, fldBLOB, fldBLOB, fldBLOB);

begin

  with FieldDesc do

  begin

    AnsiToNative(Locale, Name, szName, SizeOf(szName) - 1);

    iFldType := TypeMap[DataType];

    case DataType of

      ftString, ftBytes, ftVarBytes, ftBlob, ftMemo, ftGraphic:

        iUnits1 := Size;

      ftBCD:

        begin

          iUnits1 := 32;

          iUnits2 := Size;

        end;

    end;

    case DataType of

      ftCurrency:

        iSubType := fldstMONEY;

      ftBlob:

        iSubType := fldstBINARY;

      ftMemo:

        iSubType := fldstMEMO;

      ftGraphic:

        iSubType := fldstGRAPHIC;

    end;

  end;

end;



procedure TLDTable.EncodeIndexDesc(var IndexDesc: IDXDesc;

  const Name, Fields: string; Options: TIndexOptions);

var

  Pos: Integer;

begin

  FillChar(IndexDesc, SizeOf(IndexDesc), 0);

  with IndexDesc do

  begin

    if IsDBaseTable then

      AnsiToNative(DBLocale, Name, szTagName, SizeOf(szTagName) - 1)

    else

      AnsiToNative(DBLocale, Name, szName, SizeOf(szName) - 1);

    bPrimary := ixPrimary in Options;

    bUnique := ixUnique in Options;

    bDescending := ixDescending in Options;

    bMaintained := True;

    bCaseInsensitive := ixCaseInsensitive in Options;

    if ixExpression in Options then

    begin

      bExpIdx := True;

      AnsiToNative(DBLocale, Fields, szKeyExp, SizeOf(szKeyExp) - 1);

    end else

    begin

      Pos := 1;

      while (Pos <= Length(Fields)) and (iFldsInKey < 16) do

      begin

        aiKeyFld[iFldsInKey] :=

          FieldDefs.Find(ExtractFieldName(Fields, Pos)).FieldNo;

        Inc(iFldsInKey);

      end;

    end;

  end;

end;



function TLDTable.IsDBaseTable: Boolean;

begin

  Result := (TableType = ttDBase) or

    (CompareText(ExtractFileExt(TableName), '.DBF') = 0);

end;



{========}



procedure Register;

begin

  RegisterComponents('DBAddOns', [TLDTable]);

end;





end.

0  COMMENTS