mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-14 20:39:03 +02:00
* Small fixes and demo for TStrings.LoadFromURL
This commit is contained in:
parent
4be82217cd
commit
a0a0016f99
@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>scratch</title>
|
<title>Load stream from URL demo</title>
|
||||||
<script src="demoloadstreamfromurl.js"></script>
|
<script src="demoloadstreamfromurl.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -6,7 +6,7 @@ uses
|
|||||||
browserconsole, Classes;
|
browserconsole, Classes;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
SS : TStringStream;
|
SS,SS2,SS3 : TStringStream;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Writeln('Loading synchronously');
|
Writeln('Loading synchronously');
|
||||||
@ -18,30 +18,22 @@ begin
|
|||||||
SS.Free;
|
SS.Free;
|
||||||
end;
|
end;
|
||||||
Writeln('Loading asynchronously');
|
Writeln('Loading asynchronously');
|
||||||
SS:=TStringStream.Create('');
|
SS2:=TStringStream.Create('');
|
||||||
try
|
SS2.LoadFromURL('bytes.txt',True,procedure(Sender: tobject)
|
||||||
SS.LoadFromURL('bytes.txt',False,procedure(Sender: tobject)
|
|
||||||
begin
|
begin
|
||||||
Writeln('Loaded 2: ',SS.DataString);
|
Writeln('Loaded 2: ',SS2.DataString);
|
||||||
end
|
end
|
||||||
)
|
);
|
||||||
finally
|
|
||||||
SS.Free;
|
|
||||||
end;
|
|
||||||
Writeln('Loading non-existing file');
|
Writeln('Loading non-existing file');
|
||||||
SS:=TStringStream.Create('');
|
SS3:=TStringStream.Create('');
|
||||||
try
|
SS3.LoadFromURL('bytesnonexist.txt',True,procedure(Sender: tobject)
|
||||||
SS.LoadFromURL('bytesnonexist.txt',False,procedure(Sender: tobject)
|
|
||||||
begin
|
begin
|
||||||
Writeln('Loaded 3: ',SS.DataString);
|
Writeln('Loaded 3: ',SS3.DataString);
|
||||||
end
|
end
|
||||||
,
|
,
|
||||||
procedure(Sender: tobject; Const aError : string)
|
procedure(Sender: tobject; Const aError : string)
|
||||||
begin
|
begin
|
||||||
Writeln('Load error: ',aError);
|
Writeln('Load error: ',aError);
|
||||||
end
|
end
|
||||||
)
|
);
|
||||||
finally
|
|
||||||
SS.Free;
|
|
||||||
end;
|
|
||||||
end.
|
end.
|
||||||
|
19
demo/rtl/demoloadstringsfromurl.html
Normal file
19
demo/rtl/demoloadstringsfromurl.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Demo load strings from URL</title>
|
||||||
|
<script src="demoloadstringsfromurl.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Demo loading file from URL to TStringList</h1>
|
||||||
|
<div id="pasjsconsole">
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
rtl.run();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
88
demo/rtl/demoloadstringsfromurl.lpi
Normal file
88
demo/rtl/demoloadstringsfromurl.lpi
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="12"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
<MainUnitHasScaledStatement Value="False"/>
|
||||||
|
<Runnable Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<Title Value="demoloadstringsfromurl"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<CustomData Count="2">
|
||||||
|
<Item0 Name="MaintainHTML" Value="1"/>
|
||||||
|
<Item1 Name="PasJSWebBrowserProject" Value="1"/>
|
||||||
|
</CustomData>
|
||||||
|
<BuildModes>
|
||||||
|
<Item Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<UseFileFilters Value="True"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
</RunParams>
|
||||||
|
<Units>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="demoloadstringsfromurl.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
</Unit>
|
||||||
|
<Unit>
|
||||||
|
<Filename Value="demoloadstringsfromurl.html"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<CustomData Count="1">
|
||||||
|
<Item0 Name="PasJSIsProjectHTMLFile" Value="1"/>
|
||||||
|
</CustomData>
|
||||||
|
</Unit>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target FileExt=".js">
|
||||||
|
<Filename Value="demoloadstringsfromurl"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<UnitOutputDirectory Value="js"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<AllowLabel Value="False"/>
|
||||||
|
<CPPInline Value="False"/>
|
||||||
|
<UseAnsiStrings Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
|
<CodeGeneration>
|
||||||
|
<TargetOS Value="browser"/>
|
||||||
|
</CodeGeneration>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<GenerateDebugInfo Value="False"/>
|
||||||
|
<UseLineInfoUnit Value="False"/>
|
||||||
|
</Debugging>
|
||||||
|
</Linking>
|
||||||
|
<Other>
|
||||||
|
<CustomOptions Value="-Jeutf-8 -Jirtl.js -Jc -Jminclude"/>
|
||||||
|
<CompilerPath Value="$(pas2js)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions>
|
||||||
|
<Item>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item>
|
||||||
|
<Item>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
53
demo/rtl/demoloadstringsfromurl.lpr
Normal file
53
demo/rtl/demoloadstringsfromurl.lpr
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
program demoloadstringsfromurl;
|
||||||
|
|
||||||
|
{$mode objfpc}
|
||||||
|
|
||||||
|
uses
|
||||||
|
browserconsole, Classes;
|
||||||
|
|
||||||
|
Procedure DumpList(s : Tstrings);
|
||||||
|
|
||||||
|
Var
|
||||||
|
I : Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln('----------');
|
||||||
|
For I:=0 to S.Count-1 do
|
||||||
|
Writeln('Line[',I,'] : ',S[I]);
|
||||||
|
Writeln('----------');
|
||||||
|
end;
|
||||||
|
|
||||||
|
Var
|
||||||
|
Lst,lst2,lst3 : TStrings;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln('Loading synchronously');
|
||||||
|
Lst:=TStringList.Create;
|
||||||
|
try
|
||||||
|
Lst.LoadFromFile('bytes.txt');
|
||||||
|
DumpList(Lst);
|
||||||
|
finally
|
||||||
|
Lst.Free;
|
||||||
|
end;
|
||||||
|
Writeln('Loading asynchronously');
|
||||||
|
// We can't free the stringlist, because of the async nature
|
||||||
|
Lst2:=TStringList.Create;
|
||||||
|
Lst2.LoadFromURL('bytes.txt',True,procedure(Sender: tobject)
|
||||||
|
begin
|
||||||
|
DumpList(Lst2);
|
||||||
|
end
|
||||||
|
);
|
||||||
|
Writeln('Loading non-existing file');
|
||||||
|
// We can't free the stringlist, because of the async nature
|
||||||
|
Lst3:=TStringList.Create;
|
||||||
|
Lst3.LoadFromURL('bytesnonexist.txt',True,procedure(Sender: tobject)
|
||||||
|
begin
|
||||||
|
DumpList(Lst3);
|
||||||
|
end
|
||||||
|
,
|
||||||
|
procedure(Sender: tobject; Const aError : string)
|
||||||
|
begin
|
||||||
|
Writeln('Load error: ',aError);
|
||||||
|
end
|
||||||
|
);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user