unit main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ImgList;
function RandomString(
const len: Integer = 30;
const CharSet:
string = '
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
string;
overload;
type
TEntry =
record
User:
String[25];
Msg: TStringList;
DatumZeit:
String;
end;
TForm1 =
class(TForm)
Panel1: TPanel;
Panel2: TPanel;
BSend: TButton;
MOutput: TMemo;
MMessage: TMemo;
EUser: TEdit;
Label1: TLabel;
EDiv: TEdit;
Label2: TLabel;
BSort: TButton;
Icons: TImageList;
BRefresh: TButton;
procedure FormCreate(Sender: TObject);
procedure BSendClick(Sender: TObject);
procedure BSortClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure BRefreshClick(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Entry: TEntry;
Entries:
Array of TEntry;
AufAb: Boolean;
implementation
{$R *.dfm}
procedure GetFilesInDirectory(Directory:
string;
const Mask:
string;
List: TStrings;
WithSubDirs, ClearList: Boolean);
[...]
end;
procedure Sortieren(Aufsteigend: Boolean);
var
E: TEntry;
i, j, max: Integer;
x, y: TDateTime;
begin
E.Msg := TStringlist.Create;
max := Length(Entries);
for i:=0
to max-1
do
for j:=0
to max-1
do
begin
DateSeparator := '
.';
ShortDateFormat := '
dd.mm.yyyy';
LongTimeFormat := '
hh:nn:ss.zzz';
if Aufsteigend = True
then
begin
x := StrToDateTime(Entries[i].DatumZeit);
y := StrToDateTime(Entries[j].DatumZeit);
end
else
begin
x := StrToDateTime(Entries[j].DatumZeit);
y := StrToDateTime(Entries[i].DatumZeit);
end;
if x > y
then
begin
E := Entries[i];
Entries[i] := Entries[j];
Entries[j] := E;
end;
end;
E.Msg.Clear;
end;
procedure InitFillEntries(Liste: TStringList);
var
i, zeilen, j: Integer;
Inhalt: TStringlist;
begin
Inhalt := TStringlist.Create;
if Length(Entries) > Liste.Count
then
begin
for i := 0
to Length(Entries) - 1
do
begin
Entries[i].Msg.Clear;
Entries[i].User := '
';
Entries[i].DatumZeit := '
';
end;
end;
SetLength(Entries, Liste.Count);
for i := 0
to Length(Entries) - 1
do
begin
if FileExists(Liste[i])
then Inhalt.LoadFromFile(Liste[i])
else
begin
ShowMessage(Liste[i] + #13 + '
does not exist.');
Exit;
end;
Entries[i].User := Inhalt.Strings[0];
Entries[i].DatumZeit := Inhalt.Strings[1];
Entries[i].Msg := TSTringlist.Create;
Entries[i].Msg.BeginUpdate;
Entries[i].Msg.LoadFromFile(Liste[i]);
Entries[i].Msg.Delete(0);
Entries[i].Msg.Delete(0);
Entries[i].Msg.EndUpdate;
end;
Sortieren(AufAb);
Inhalt.Free;
end;
procedure PassEntries;
var
i, c, j: Integer;
L, laden: TStringlist;
Liste: TStringlist;
s, dir:
String;
begin
L := TStringlist.Create;
Liste := TStringlist.Create;
Laden := TStringlist.Create;
dir := ExtractFilePath(ParamStr( 0 ))+'
dbchat\';
GetFilesInDirectory(dir, '
*.txt', Liste, False, True);
L.BeginUpdate;
InitFillEntries(Liste);
//Array Füllen
for i := 0
to Length(Entries) - 1
do
begin
L.BeginUpdate;
L.Add(Entries[i].User);
L.Add(Entries[i].DatumZeit);
L.Add('
');
L.Add(Trim(Entries[i].Msg.Text));
for c := 0
to 19
do s := s + Form1.EDiv.Text;
L.Add(s);
s := '
';
end;
L.EndUpdate;
Form1.MOutput.Lines.Clear;
Form1.MOutput.Lines.Assign(L);
Liste.Free;
laden.Free;
L.Free;
end;
function RandomString(
const len: Integer;
const CharSet:
string):
string;
[...]
end;
procedure TForm1.BSendClick(Sender: TObject);
[...]
end;
procedure TForm1.BSortClick(Sender: TObject);
begin
[...]
end;
procedure TForm1.BRefreshClick(Sender: TObject);
begin
PassEntries;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
dir :
string;
begin
Randomize;
// Get the current directory
dir := GetCurrentDir;
if DirectoryExists('
dbchat') = True
then
begin
AufAb := True;
PassEntries;
end
else
begin
CreateDir('
dbchat');
ShowMessage('
Directory created:' + #13 + dir + '
dbchat');
end;
MMessage.Lines.Clear;
end;
procedure TForm1.FormDestroy(Sender: TObject);
var
i: Integer;
begin
//Leeren
for i := 0
to Length(Entries) - 1
do
begin
Entries[i].Msg.Clear;
Entries[i].User := '
';
Entries[i].DatumZeit := '
';
end;
SetLength(Entries, 0);
end;
end.