mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 00:02:03 +02:00
LazUtils: Add simple functions SaveStringToFile and LoadStringFromFile. Rename SaveStringToFile in DialogProcs.
This commit is contained in:
parent
103d9f42e1
commit
4967237fb1
@ -105,6 +105,10 @@ function StringCase(const AString: String; const ACase: array of String;
|
|||||||
function SamePChar(P1, P2: PChar): boolean;
|
function SamePChar(P1, P2: PChar): boolean;
|
||||||
function StrLScan(P: PChar; c: Char; MaxLen: Cardinal): PChar;
|
function StrLScan(P: PChar; c: Char; MaxLen: Cardinal): PChar;
|
||||||
|
|
||||||
|
// To and from a file.
|
||||||
|
function SaveStringToFile(const aString, aFileName: String): Boolean;
|
||||||
|
function LoadStringFromFile(const aFileName: String): String;
|
||||||
|
|
||||||
// Like IsValidIdent() in FPC 3.1.
|
// Like IsValidIdent() in FPC 3.1.
|
||||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||||
StrictDots: Boolean = False): Boolean;
|
StrictDots: Boolean = False): Boolean;
|
||||||
@ -1400,6 +1404,34 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function SaveStringToFile(const aString, aFileName: String): Boolean;
|
||||||
|
var
|
||||||
|
fs: TFileStream;
|
||||||
|
begin
|
||||||
|
Result:=False;
|
||||||
|
fs:=TFileStream.Create(aFileName, fmCreate);
|
||||||
|
try
|
||||||
|
fs.Write(aString[1], length(aString));
|
||||||
|
Result:=True;
|
||||||
|
finally
|
||||||
|
fs.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function LoadStringFromFile(const aFileName: String): String;
|
||||||
|
var
|
||||||
|
fs: TFileStream;
|
||||||
|
begin
|
||||||
|
fs:=TFileStream.Create(aFileName, fmOpenRead);
|
||||||
|
try
|
||||||
|
SetLength(Result, fs.Size);
|
||||||
|
if Result<>'' then
|
||||||
|
fs.Read(Result[1],length(Result));
|
||||||
|
finally
|
||||||
|
fs.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
function LazIsValidIdent(const Ident: string; AllowDots: Boolean = False;
|
||||||
StrictDots: Boolean = False): Boolean;
|
StrictDots: Boolean = False): Boolean;
|
||||||
// This is a copy of IsValidIdent from FPC 3.1.
|
// This is a copy of IsValidIdent from FPC 3.1.
|
||||||
|
@ -2912,7 +2912,7 @@ begin
|
|||||||
List:=TStringList.Create;
|
List:=TStringList.Create;
|
||||||
try
|
try
|
||||||
WriteNode(List,BrowseTreeView.Items.GetFirstNode);
|
WriteNode(List,BrowseTreeView.Items.GetFirstNode);
|
||||||
Result:=SaveStringToFile(Filename,List.Text,[],
|
Result:=SaveLazStringToFile(Filename,List.Text,[],
|
||||||
'exporting identifiers as text');
|
'exporting identifiers as text');
|
||||||
finally
|
finally
|
||||||
List.Free;
|
List.Free;
|
||||||
|
@ -111,7 +111,7 @@ function ForceDirectoryInteractive(Directory: string;
|
|||||||
ErrorButtons: TMsgDlgButtons = []): TModalResult;
|
ErrorButtons: TMsgDlgButtons = []): TModalResult;
|
||||||
function DeleteFileInteractive(const Filename: string;
|
function DeleteFileInteractive(const Filename: string;
|
||||||
ErrorButtons: TMsgDlgButtons = []): TModalResult;
|
ErrorButtons: TMsgDlgButtons = []): TModalResult;
|
||||||
function SaveStringToFile(const Filename, Content: string;
|
function SaveLazStringToFile(const Filename, Content: string;
|
||||||
ErrorButtons: TMsgDlgButtons; const Context: string = ''
|
ErrorButtons: TMsgDlgButtons; const Context: string = ''
|
||||||
): TModalResult;
|
): TModalResult;
|
||||||
function ConvertLFMToLRSFileInteractive(const LFMFilename,
|
function ConvertLFMToLRSFileInteractive(const LFMFilename,
|
||||||
@ -608,7 +608,7 @@ begin
|
|||||||
until false;
|
until false;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SaveStringToFile(const Filename, Content: string;
|
function SaveLazStringToFile(const Filename, Content: string;
|
||||||
ErrorButtons: TMsgDlgButtons; const Context: string): TModalResult;
|
ErrorButtons: TMsgDlgButtons; const Context: string): TModalResult;
|
||||||
var
|
var
|
||||||
fs: TFileStream;
|
fs: TFileStream;
|
||||||
|
@ -1163,7 +1163,7 @@ begin
|
|||||||
tctSource:
|
tctSource:
|
||||||
Converter.Source:=CodeBuf.Source;
|
Converter.Source:=CodeBuf.Source;
|
||||||
tctFile:
|
tctFile:
|
||||||
Result:=SaveStringToFile(Converter.Filename,CodeBuf.Source,[])=mrOk;
|
Result:=SaveLazStringToFile(Converter.Filename,CodeBuf.Source,[])=mrOk;
|
||||||
tctStrings:
|
tctStrings:
|
||||||
CodeBuf.AssignTo(Converter.Strings,true);
|
CodeBuf.AssignTo(Converter.Strings,true);
|
||||||
tctCodeBuffer:
|
tctCodeBuffer:
|
||||||
|
@ -5348,8 +5348,8 @@ begin
|
|||||||
and (not AnUnitInfo.IsVirtual) then begin
|
and (not AnUnitInfo.IsVirtual) then begin
|
||||||
LRJFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lrj');
|
LRJFilename:=ChangeFileExt(AnUnitInfo.Filename,'.lrj');
|
||||||
DebugLn(['SaveUnitComponent save lrj: ',LRJFilename]);
|
DebugLn(['SaveUnitComponent save lrj: ',LRJFilename]);
|
||||||
Result:=SaveStringToFile(LRJFilename,Grubber.Grubbed.Text,
|
Result:=SaveLazStringToFile(LRJFilename,Grubber.Grubbed.Text,
|
||||||
[mbIgnore,mbAbort],AnUnitInfo.Filename);
|
[mbIgnore,mbAbort],AnUnitInfo.Filename);
|
||||||
if (Result<>mrOk) and (Result<>mrIgnore) then exit;
|
if (Result<>mrOk) and (Result<>mrIgnore) then exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -2488,8 +2488,8 @@ begin
|
|||||||
PkgList.Free;
|
PkgList.Free;
|
||||||
end;
|
end;
|
||||||
StaticPckIncludeFile:=ConfigDir+'staticpackages.inc';
|
StaticPckIncludeFile:=ConfigDir+'staticpackages.inc';
|
||||||
Result:=SaveStringToFile(StaticPckIncludeFile,StaticPackagesInc,[],
|
Result:=SaveLazStringToFile(StaticPckIncludeFile,StaticPackagesInc,[],
|
||||||
lisPkgMangstaticPackagesConfigFile);
|
lisPkgMangstaticPackagesConfigFile);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TLazPackageGraph.IsCompiledInBasePackage(PackageName: string): boolean;
|
function TLazPackageGraph.IsCompiledInBasePackage(PackageName: string): boolean;
|
||||||
@ -5764,9 +5764,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// save source
|
// save source
|
||||||
Result:=SaveStringToFile(SrcFilename,Src,[],lisPkgMangpackageMainSourceFile);
|
Result:=SaveLazStringToFile(SrcFilename,Src,[],lisPkgMangpackageMainSourceFile);
|
||||||
if Result<>mrOk then begin
|
if Result<>mrOk then begin
|
||||||
DebugLn('Error: (lazarus) [TLazPackageGraph.SavePackageMainSource] SaveStringToFile ',SrcFilename,' failed');
|
DebugLn('Error: (lazarus) [TLazPackageGraph.SavePackageMainSource] SaveLazStringToFile ',SrcFilename,' failed');
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user