Автор: delphi | 14.12.2007 в 9:21 | Рубрики: Базы данных

Вот код печати структуры таблицы Paradox, состряпанный на скорую руку. Предполагается, что компонент Table имеет имя Table1.

procedure TForm1.Button1Click(Sender: TObject);
const
FieldTypes: array[0..16] of string[10] = (’Unknown’, ‘String’, ‘Smallint’,
‘Integer’, ‘Word’, ‘Boolean’, ‘Float’, ‘Currency’, ‘BCD’, ‘Date’, ‘Time’,
‘DateTime’, ‘Bytes’, ‘VarBytes’, ‘Blob’, ‘Memo’, ‘Graphic’);
var
i, nX, nY, nHeight, nWidth: Integer;
rtxtMetric: TTextMetric;
s: array[0..3] of string[10];
begin
with Table1.FieldDefs, Printer do
begin
Update;
PrinterIndex := -1;
Title := ‘Структура ‘ + Table1.TableName;
BeginDoc;
nX := 0;
nY := 0;
WinProcs.GetTextMetrics(Canvas.Handle, rtxtMetric);
nHeight := rtxtMetric.tmHeight;
nWidth := rtxtMetric.tmAveCharWidth;
for i := 0 to Count - 1 do
begin
s[0] := IntToStr(Items[i].FieldNo) + #9;
s[1] := Items[i].Name + #9;
s[2] := FieldTypes[Ord(Items[i].DataType)] + #9;
s[3] := IntToStr(Items[i].Size);
Canvas.TextOut(nX, nY, s[0]);
Inc(nX, Length(s[0]) * nWidth);
Canvas.TextOut(nX, nY, s[1]);
Inc(nX, Length(s[1]) * nWidth);
Canvas.TextOut(nX, nY, s[2]);
Inc(nX, Length(s[2]) * nWidth);
Canvas.TextOut(nX, nY, s[3]);
nX := 0;
nY := i * nHeight;
end;
EndDoc;
end;
end;

Кто-нибудь знает как изменить месторасположение файла PDOXUSRS.NET во время выполнения программы?

DbiSetProp(hSessionHandle, sesNetFile, pchar(’c:\newdir’));

Для получения дескриптора сеанса, если вы используете сессию по умолчанию, необходимо вызвать DbiGetCurrSession .

Для dBase:

uses
DbiProcs;

with Table do
begin
OldState := Active;
Close;
Exclusive := True;
Open;

DbiPackTable(DBHandle, Handle, nil, nil, True);
{^ здесь можно добавить check()}

Close;
Exclusive := False;
Active := OldState;
{ при желании можно сохранить закладку }
end;
Читать полностью…

- Алло, техотдел? Я пароль набираю - а меня не пускают.
- Значит, правильно набирать надо.
- Я правильно набираю! Пять звездочек!

uses Bde, SysUtils, dbtables, windows;

function StrToOem(const AnsiStr: string): string;
begin
SetLength(Result, Length(AnsiStr));
if Length(Result) 0 then
CharToOem(PChar(AnsiStr), PChar(Result));
end;

function TablePasswort(var Table: TTable; password: string): Boolean;
var
pTblDesc: pCRTblDesc;
hDb: hDBIDb;
begin
Result := False;
with Table do
begin
if Active and (not Exclusive) then Close;
if (not Exclusive) then Exclusive := True;
if (not Active) then Open;
hDB := DBHandle;
Close;
end;
GetMem(pTblDesc, SizeOf(CRTblDesc));
FillChar(pTblDesc^, SizeOf(CRTblDesc), 0);
with pTblDesc^ do
begin
StrPCopy(szTblName, StrToOem(Table.TableName));
szTblType := szParadox;
StrPCopy(szPassword, StrToOem(Password));
bPack := True;
bProtected := True;
end;
if DbiDoRestructure(hDb, 1, pTblDesc, nil, nil, nil, False) DBIERR_NONE then Exit;
if pTblDesc nil then FreeMem(pTblDesc, SizeOf(CRTblDesc));
Result := True;
end;

{
The table component’s ACTIVE property must be set to FALSE
(If it is active before you have added the pasword, you will be prompted).
Then, put this code in the handler for the form’s OnCreate event:
}
Session.AddPassword(’My secret password’);
Table1.Active := True;

{
Once you close the table, you can remove the password with
RemovePassword(’My secret password’),
or you can remove all current passwords with RemoveAllPasswords.
(Note: This is for Paradox tables only.)
}