Forum > General
Value of string disappears
Davidous:
Hello,
I'm new to Lazarus, I did a lot of programming in Delphi 7. Now I started to write my programs from Delphi to Lazarus, but I faced a very strange thing.
My program loads a text file to a stringlist. Then from this stringlist I need some lines as a string. I give these values to different strings. Then my program goes on and after a few more lines in the program when I check my string values I can see, that they are all ???... I suppose that means that they are empty. It is a really simple code, I don't know what could cause the problem. Please help me!
oD:=TOpenDialog.Create(self);
oD.InitialDir := GetCurrentDir;
oD.Title:='Kérem válassza ki a mérési fájlt!';
oD.Filter:='Txt fájlok|*.txt';
oD.Execute;
list:=TStringList.Create;
list.LoadFromFile(oD.FileName);
tr:=AnsiMidStr(list[0],22,length(list[0])-21);
d:=AnsiMidStr(list[10],15,length(list[10])-14);
fn:=ExtractFileName(oD.FileName);
dl:=TStringList.Create;
dl.Delimiter:='.';
dl.DelimitedText:=d;
For w:=0 To 20 Do
Begin
If AnsiLeftStr(fn,4)='left' Then
Begin
If (AnsiMidStr(list[w],19,length(list[w])-18)='vorwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='steigend') Then
Begin
oldbj:='b';
Break;
end
Else If (AnsiMidStr(list[w],19,length(list[w])-18)='rückwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='fallend') Then
Begin
oldbj:='b';
Break;
end
Else If (AnsiMidStr(list[w],19,length(list[w])-18)='vorwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='fallend') Then
Begin
oldbj:='j';
Break;
end
Else If (AnsiMidStr(list[w],19,length(list[w])-18)='rückwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='steigend') Then
Begin
oldbj:='j';
Break;
end;
end
Else If AnsiLeftStr(fn,4)='righ' Then
Begin
If (AnsiMidStr(list[w],19,length(list[w])-18)='vorwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='steigend') Then
Begin
oldbj:='j';
Break;
end
Else If (AnsiMidStr(list[w],19,length(list[w])-18)='rückwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='fallend') Then
Begin
oldbj:='j';
Break;
end
Else If (AnsiMidStr(list[w],19,length(list[w])-18)='vorwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='fallend') Then
Begin
oldbj:='b';
Break;
end
Else If (AnsiMidStr(list[w],19,length(list[w])-18)='rückwärts') And (AnsiMidStr(list[w+1],20,length(list[w+1])-19)='steigend') Then
Begin
oldbj:='b';
Break;
end;
end;
end;
Thaddy:
Well, compile in mode delphi. Your code works, but I had to do a lot to write a compilable version.
Davidous:
I'm sorry, but I still can't get it to work. I set the compiler mode to delphi:
{$mode delphi}
but the result is the same. Strings are not stored for some reason. :(
Blaazen:
What OS do you use and what is format of the text file (UTF8 or so)?
This may be related to different LineEnding in Windows and Linux.
Davidous:
I use win10 but I also tested it on win7 with the same results.
The text file is UTF-8.
Navigation
[0] Message Index
[#] Next page