unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TCVSClass=Class
private
Ffn:
String;
Fsl:TStringList;
Fll:TList;
function GetColumns: Integer;
function GetRows: Integer;
public
Constructor Create(
const fn:
String;aDelimiter:Char);
Destructor Destroy;
Function GetElement(x, y: Integer):
String;
published
Property Columns:Integer
read GetColumns;
Property Rows:Integer
read GetRows;
End;
TForm1 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TCVSClass }
constructor TCVSClass.Create(
const fn:
String;aDelimiter:Char);
var
i:Integer;
begin
FFn := fn;
Fsl := TStringList.Create;
Fsl.LoadFromFile(fn);
Fll := TList.Create;
for I := 0
to Fsl.Count - 1
do
begin
Fll.Add(TStringList.Create);
with TStringList(FLL[FLL.Count-1])
do
begin
Delimiter := aDelimiter;
DelimitedText := Fsl[i];
end;
end;
end;
destructor TCVSClass.Destroy;
var
i:Integer;
begin
Fsl.Free;
for I := 0
to Fll.Count - 1
do TStringList(Fll[i]).free;
Fll.Free;
end;
function TCVSClass.GetColumns: Integer;
begin
if Fll.Count>0
then
Result := TStringList(FLL[0]).count
else Result := 0;
end;
function TCVSClass.GetElement(x, y: Integer):
String;
begin
if (y > -1)
and (y < Fll.Count)
then
begin
if (x > -1)
and ( x < TStringList(FLL[y]).Count)
then
begin
Result := TStringList(FLL[y])[X];
end else Result := '
';
end
else Result := '
';
end;
function TCVSClass.GetRows: Integer;
begin
Result := Fll.Count;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x,y:Integer;
begin
With TCVSClass.Create('
C:\temp\Mappe1.csv','
;')
do
begin
for x := 0
to Rows
do
for y := 0
to Columns
do
Memo1.Lines.Add(GetElement(x,y));
end;
end;
end.