Autor Beitrag
Sauger Chris
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Mo 20.10.08 17:59 
Moin und zwar :)

ich will aus einer datei(Sql Dump) bestimmte stings in eine Listview komp. Adden klappt auch so nur erstellt mir die funktion warum auch immer zig leere items in der komp. könntet ihr mal über meinen source drüber gehen.

ps. soll so eine art Datenbank filter werden wo halt die tabel namen raus filtert :)

Beispiel String:
CREATE TABLE `hp_user` (

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.loadDBClick(Sender: TObject);
var i,
    Position1,
    Position2,
    Position3    : integer;
    checkstring  : string;
begin
konf            := TStringList.Create;
konf.Sorted     := true;                   //alphabetisch sortieren
konf.Duplicates := dupIgnore;              //doppelte items ignorieren
if opendialog1.Execute then
begin
konf.LoadFromFile(opendialog1.FileName);
try
for i:=0 to konf.Count -1 do
begin
checkstring := konf.Strings[i];
   position1   := Pos('CREATE TABLE `',konf.Strings[i])+14;   // start position suchen und such string abziehen
   position2   := Pos('` (',konf.Strings[i]);              // end position ermitteln
   Position3   := Position2-Position1;
  ListView1.Items.Add.Caption:= (Copy(checkstring, Position1,Position3));//results in listview1 schreiben
  listview1.Width := 200;
end;



hoffe ihr könnt mir helfen danke schon mal im vor raus =)

mfg euer chris


Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Mo 20.10.2008 um 19:29
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 20.10.08 20:25 
Meine Glaskugel sagt mir, dass die Datei nicht nur aus Zeilen besteht, die diesem Format übereinstimmen. Oder hab ich diesen verschwommenen Nebel links unten falsch gedeutet? ;)

Zeig doch mal die Datei. :idea:

Was du auf jeden Fall machen könntest, wäre eine kleine Kontrolle, ob überhaupt der Startstring gefunden wurde:

ausblenden Delphi-Quelltext
 
18:
19:
{ ... }
   position1   := Pos('CREATE TABLE `',konf.Strings[i])+14;   // start position suchen und such string abziehen 
   if position1 = 0 then Continue;
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Mo 20.10.08 21:04 
man man man so einfach kanns gehen ^^
hatte schon mit position1 rum bespielt wen bestimmtes zeichen an einer stelle ist usw. naja

thx Yogu geht nu =)

hier der code
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
for i:=0 to konf.Count -1 do
begin
checkstring := konf.Strings[i];
 position1   := Pos('CREATE TABLE `',konf.Strings[i])+14;   // start position suchen
 position2   := Pos('` (',konf.Strings[i]);              // end position ermitteln
 Position3   := Position2-Position1;
  if position1 = 14 then
  else
  ListView1.Items.Add.Caption:= (Copy(checkstring, Position1,Position3));//schreiben in listview1
  listview1.Width := 200;