You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done.
procedure foo()
var
str1: String;
begin
str1:=StringReplace('Hello World...','...',[rfReplaceAll, rfIgnoreCase]);
// Output of str1 => "Hello World"
end
73
Delphi
Windows - Prompt Errorlevel
Errorlevel setzen
//...
var
errorlevel: Integer;
begin
if cond1=cond2 then errorlevel:=0;
if cond1<>cond2 then errorlevel:=1;
halt(errorlevel);
end.
74
Delphi
Typenkonvertierung
String in Integer konvertieren
MyInt:=StrToInt('125');
77
Delphi
Filehandling
Applikations-/Script-Verzeichnis ermitteln
AppPath:=ExtractFilePath(Application.Exename);
78
Delphi
Anwendungskonfigurationsdateien
INI-Datei lesen
uses
IniFiles;
var
iniMem: TMemIniFile; // ini-File (ready only one time)
// Load the ini-information once - maybe at startup
function TMyForm.LoadIniFile:boolean;
var
SL : TStringList;
return : Boolean;
iniFile : String;
begin
iniFile:='myFormConfig.ini';
return:=true;
if not FileExists(ExtractFilePath(Application.Exename)+iniFile) then
begin
MessageDlg('ini-File not found!', mtError, [mbOK], 0);
return:=false;
end;
if not return then halt;
iniMem:=TMemIniFile.Create('');
SL:=TStringList.Create;
SL.LoadFromFile(ExtractFilePath(Application.Exename)+iniFile);
iniMem.SetStrings(SL);
LoadIniFile:=return;
end;
procedure TMyForm.DoThis;
begin
ShowMessage(iniMem.ReadString('Section','Attribute','Default-Value'));
end;
116
Delphi
Strings
String nach einem Teilstring durchsuchen
searchFor:='this';
text:='this is a simple text';
if pos(searchFor,text)>0 then
begin
ShowMessage('found');
end;
177
Delphi
Filehandling
Prüfen ob Datei existiert
procedure TForm1.CheckIfFileExists();
var
filePath : String;
begin
filePath:='C:\User\myUser\text.txt';
if FileExists(filePath) then
begin
ShowMessage('There it is! ;-)');
end
else
begin
ShowMessage('Whow, file is missing at this place :-(');
end;
end;
221
Delphi
Strings
Position eines Teilstrings finden
searchFor:='simple';
text:='this is a simple text';
ShowMessage(IntToStr(pos(searchFor,text)));
// 11