home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1999 March
/
Chip_1999-03_cd.bin
/
zkuste
/
delphi
/
INFO
/
DI9806BT.ZIP
/
fixtext
/
FIXTEXTF.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1997-12-29
|
3KB
|
116 lines
unit Fixtextf;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
CreateBtn: TButton;
ReadBtn: TButton;
DeleteBtn: TButton;
Label1: TLabel;
ReadCount: TLabel;
procedure CreateBtnClick(Sender: TObject);
procedure ReadBtnClick(Sender: TObject);
procedure DeleteBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
TAddress = record
name: array[1..35] of Char;
addr: array[1..35] of Char;
city: array[1..18] of Char;
state: array[1..2] of Char;
zip: array[1..10] of Char;
delimiter: array[1..2] of Char;
end;
procedure PasToArray(const str: String;
var arr: array of Char);
{
Copies a Pascal String to a Char array. The
array is padded with blanks.
}
var
i, j: Word;
begin
{Copy the string to the array.}
for i := 1 to Length(str) do arr[i - 1] := str[i];
{Fill the array with spaces in case the
string is shorter than the array.}
j := i + 1;
for i := j to High(arr) do arr[i] := ' ';
end;
procedure TForm1.CreateBtnClick(Sender: TObject);
const
MaxRecs = 100;
var
buff: array[1..MaxRecs] of TAddress;
addrFile: File;
i, count: Integer;
begin
AssignFile(addrFile, 'addr.dat');
Rewrite(addrFile, SizeOf(TAddress));
{initialize the buffer}
FillChar(buff,SizeOf(Buff),#0); {added by RLV on 12/29/97}
{Put 100 records into the buffer.}
for i := 1 to MaxRecs do
with buff[i] do
begin
PasToArray('John Doe', name);
PasToArray('123 East Main Street', addr);
PasToArray('New York', city);
PasToArray('NY', state);
PasToArray('55555-5555', zip);
delimiter[1] := #13;
delimiter[2] := #10;
end;
{Write 100 buffers (10,000 records.}
for i := 1 to 100 do
BlockWrite(addrFile, buff, MaxRecs, count);
System.Close(addrFile);
end;
procedure TForm1.ReadBtnClick(Sender: TObject);
const
MaxRecs = 100;
var
buff: array[1..MaxRecs] of TAddress;
addrFile: File;
total,
count: Integer;
begin
AssignFile(addrFile, 'addr.dat');
Reset(addrFile, SizeOf(TAddress));
{Read the file 100 records at a time.}
total := 0;
repeat
BlockRead(addrFile, buff, MaxRecs, count);
total := total + count;
ReadCount.Caption := IntToStr(total);
until count = 0;
System.Close(addrFile);
end;
procedure TForm1.DeleteBtnClick(Sender: TObject);
begin
DeleteFile('addr.dat');
end;
end.