unit MeD1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ExtCtrls, StrUtils, ShellAPI, Menus;
type
TForm1 =
class(TForm)
Panel1: TPanel;
StringGrid1: TStringGrid;
Panel2: TPanel;
StringGrid2: TStringGrid;
Panel3: TPanel;
Label1: TLabel;
Panel4: TPanel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
MainMenu1: TMainMenu;
File1: TMenuItem;
ReStream1: TMenuItem;
LoadIntra1: TMenuItem;
LoadInter1: TMenuItem;
SaveIntra1: TMenuItem;
SaveInter1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure LoadIntra1Click(Sender: TObject);
procedure LoadInter1Click(Sender: TObject);
procedure SaveIntra1Click(Sender: TObject);
procedure SaveInter1Click(Sender: TObject);
procedure ReStream1Click(Sender: TObject);
private
{ Private declarations }
Procedure load_Grid(Grid: TStringGrid);
Procedure save_Grid(Grid: TStringGrid);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
load_grid(StringGrid1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
save_grid(StringGrid1);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
load_grid(StringGrid2);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
save_grid(StringGrid2);
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
Close;
end;
Procedure TForm1.load_Grid(Grid: TStringGrid);
Var
X, Y, ActPos, PrevPos : Integer;
sl : TStrings;
Begin
OpenDialog1.InitialDir := '
Matrices';
If Not OpenDialog1.Execute
Then Exit;
sl := TStringList.Create;
Try
// Öffne Datei in StringList
sl.LoadFromFile(OpenDialog1.FileName);
// laufe durch die sl
For Y := 0
To pred(sl.Count)
Do
Begin
// Spalte 0
X := 0;
PrevPos := 1;
// suche das erste ","
ActPos := PosEx('
,', Sl[Y], PrevPos);
// verlasse die Schleife wenn kein "," mehr gefunden wurde
While ActPos > 0
Do
Begin
// schreibe in die Zelle den Text zwischen dem vorherigen "," und dem gefundenen ","
Grid.Cells[X, Y] := Copy(sl[Y], PrevPos, (ActPos - PrevPos));
// Postion des letzten Kommas
PrevPos := succ(ActPos);
// suche das nächste ","
ActPos := PosEx('
,', Sl[Y], PrevPos);
inc(X);
End;
// zum Schluss noch den Text ab dem zuletzt gefundenen Komma in die Zelle
Grid.Cells[X, Y] := Copy(sl[Y], PrevPos, Length(sl[Y]));
End;
Finally
// Freigeben der sl
FreeAndNil(SL);
End;
End;
Procedure TForm1.save_Grid(Grid: TStringGrid);
Var
X, Y : Integer;
sl : TStrings;
TempStr :
String;
Begin
SaveDialog1.InitialDir := '
Matrices';
If Not SaveDialog1.Execute
Then Exit;
sl := TStringList.Create;
Try
With Grid
Do
For Y := 0
To pred(Grid.RowCount)
Do
Begin
// Leeren des TempStr vor jeder Zeile
TempStr := '
';
For X := 0
To pred(Grid.ColCount)
Do
TempStr := TempStr + Trim(Cells[X, Y]) + '
,';
// Hinzufügen von TempStr zur sl
// in der letzten Zeile muss das letzte Komma abgeschnitten werden
If Y = pred(Grid.RowCount)
Then
sl.Add(Copy(TempStr, 1, Length(TempStr) - 1))
Else
sl.Add(TempStr);
End;
// Speichern der StringList
sl.SaveToFile(SaveDialog1.FileName);
Finally
// Freigeben der sl
FreeAndNil(SL);
End;
End;
procedure TForm1.LoadIntra1Click(Sender: TObject);
begin
Button1.Click;
end;
procedure TForm1.LoadInter1Click(Sender: TObject);
begin
Button3.Click;
end;
procedure TForm1.SaveIntra1Click(Sender: TObject);
begin
Button2.Click;
end;
procedure TForm1.SaveInter1Click(Sender: TObject);
begin
button4.Click;
end;
procedure TForm1.ReStream1Click(Sender: TObject);
begin
ShellExecute(0,
Nil, PChar('
ReStream\ReStream.exe'),
Nil,
Nil, SW_NORMAL);
end;
end.