Forum > General
crashing app when url is changed
madref:
I have this form
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type { TForm_Test } TForm_Test = class(TForm) Button1: TButton; Button2: TButton; Memo_Test: TMemo; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private public end;When I press button 2 the following code is run:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm_Test.Button2Click(Sender: TObject);var s: String; extractor: THtmlTextExtractor; i : integer; begin// s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=55668&ShowGameSheet=1'); s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=55668'); if s <> '' then begin// SaveStringToFile(s, '/users/madref/documents/text.html'); Memo_Test.Clear; extractor := THTMLTextExtractor.Create; try s := extractor.ExtractFromHtml(s); if FileExists (UserDir + 'sheet.txt') then DeleteFile (UserDir + 'sheet.txt'); SaveStringToFile(s, UserDir + 'sheet.txt'); Memo_Test.Lines.LoadFromFile(UserDir + 'sheet.txt'); if FileExists (UserDir + 'sheet.txt') then DeleteFile (UserDir + 'sheet.txt'); i := 0;// i := FindInMemo (Memo_Test, 'Score A', i+1); i := FindMemoLineNumber (Memo_Test, 'Score A', i+1); ShowMessage (i.ToString); ShowMessage (Memo_Test.Lines[i]); Memo_Test.SelStart := i; Memo_Test.SetFocus; finally extractor.Free; end; end;end;This works all well. But when I change the url to:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=52600');The app crashed.
What am I doing wrong?
p.s. the attachment contains all other functions, procedures & types
jamie:
Looks like you are using the class directly?
I could be wrong but I am pretty sure you need to first create an instance of the
client..
MyInstance :TFpHttpClinent;
Begin // In code
MyInstance := TFpHttpClient.Create(Nil);
// from there you do as you please but using MyStance, not the Class.
Example
S := MyInstance.Simpleget(' ,,,,,,');
and somewhere you need the free this instance when done..
You could also do this..
With TFpClient.Create(nil) do
begin
// Your code;
Free;
End;
That creates a background instance within the block.
Thausand:
--- Quote from: jamie on March 26, 2019, 10:33:54 pm ---Looks like you are using the class directly?
I could be wrong but I am pretty sure you need to first create an instance of the
client..
--- End quote ---
class procedure so works. see https://github.com/graemeg/freepascal/blob/master/packages/fcl-web/src/base/fphttpclient.pp#L198
instance like say you, do more control but not have to.
add: my english bad. better explain https://www.askingbox.com/question/lazarus-get-html-of-a-website
madref:
The strange thing is that it works in 2.0.0 and not in 2.1.0 Trunk r60784
I am at a total loss here
madref:
It looks like something is wrong with the TMemo.
Does any have a suggestion?
Navigation
[0] Message Index
[#] Next page