Example Delphi Using Text File in OOP: ![]()
//Dependent on structure of text file
Function Extract(Var Tp:String):String;
Var
Posi: Integer;
Begin
Posi:= pos('#',Tp);
Result:= Copy(Tp,1,posi-1);
Delete(Tp,1,posi)
End;
constructor TSpyArray.create;
Var
RamFile: TextFile;
Temp, First, Second, City: string;
begin
Size:= 0;
AssignFile(RamFile,'testdata.txt');
If FileExists('testdata.txt')
Then Reset(RamFile)
Else Rewrite(RamFile);
Reset(RamFile);
While not EOF (RamFile) do
begin
readLn(RamFile, Temp);
First:= Extract(Temp);
Second:= Extract(Temp);
City:= Extract(Temp);
Inc(Size);
SpyArr[size]:= spy.create(First,Second,City); //Instantiating the class
end;
CloseFile(RamFile);//Closes the text file to ensure no corruption of data.
end;
|
Object Orientated Programming: ![]() Current Tutorial: |


Using Text Files in OOP


