Recent

Author Topic: crashing app when url is changed  (Read 8430 times)

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
crashing app when url is changed
« on: March 26, 2019, 05:10:04 pm »
I have this form
Code: Pascal  [Select][+][-]
  1. type
  2.  
  3.   { TForm_Test }
  4.  
  5.   TForm_Test = class(TForm)
  6.     Button1: TButton;
  7.     Button2: TButton;
  8.     Memo_Test: TMemo;
  9.     procedure Button1Click(Sender: TObject);
  10.     procedure Button2Click(Sender: TObject);
  11.   private
  12.  
  13.  
  14.   public
  15.  
  16.  
  17.   end;
When I press button 2 the following code is run:
Code: Pascal  [Select][+][-]
  1. procedure TForm_Test.Button2Click(Sender: TObject);
  2. var
  3.   s: String;
  4.   extractor: THtmlTextExtractor;
  5.   i : integer;
  6.  
  7.  
  8. begin
  9. //  s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=55668&ShowGameSheet=1');
  10.   s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=55668');
  11.   if s <> '' then begin
  12. //    SaveStringToFile(s, '/users/madref/documents/text.html');
  13.     Memo_Test.Clear;
  14.     extractor := THTMLTextExtractor.Create;
  15.     try
  16.       s := extractor.ExtractFromHtml(s);
  17.       if FileExists (UserDir + 'sheet.txt') then DeleteFile (UserDir + 'sheet.txt');
  18.       SaveStringToFile(s, UserDir + 'sheet.txt');
  19.       Memo_Test.Lines.LoadFromFile(UserDir + 'sheet.txt');
  20.       if FileExists (UserDir + 'sheet.txt') then DeleteFile (UserDir + 'sheet.txt');
  21.       i := 0;
  22. //      i := FindInMemo (Memo_Test, 'Score A', i+1);
  23.       i := FindMemoLineNumber (Memo_Test, 'Score A', i+1);
  24.  
  25.  
  26.       ShowMessage (i.ToString);
  27.       ShowMessage (Memo_Test.Lines[i]);
  28.       Memo_Test.SelStart := i;
  29.       Memo_Test.SetFocus;
  30.     finally
  31.       extractor.Free;
  32.     end;
  33.   end;
  34. end;
This works all well. But when I change the url to:
Code: Pascal  [Select][+][-]
  1.   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
« Last Edit: March 26, 2019, 05:13:57 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

jamie

  • Hero Member
  • *****
  • Posts: 6131
Re: crashing app when url is changed
« Reply #1 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..

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.
The only true wisdom is knowing you know nothing

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: crashing app when url is changed
« Reply #2 on: March 26, 2019, 11:17:47 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..
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
« Last Edit: March 27, 2019, 12:44:02 am by Thausand »

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #3 on: March 26, 2019, 11:26:56 pm »
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
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #4 on: March 26, 2019, 11:37:24 pm »
It looks like something is wrong with the TMemo.
Does any have a suggestion?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: crashing app when url is changed
« Reply #5 on: March 27, 2019, 12:00:00 am »
It looks like something is wrong with the TMemo.
Does any have a suggestion?
What error give ?

If not work write exception handle see http://wiki.freepascal.org/Exceptions and look example 2 http://www.delphibasics.co.uk/Article.asp?Name=Exceptions
« Last Edit: March 27, 2019, 12:05:11 am by Thausand »

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #6 on: March 27, 2019, 12:20:20 am »
I get:
Code: [Select]
....raised exception class.
Debugger stopped with reason: signal SIGABRT
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: crashing app when url is changed
« Reply #7 on: March 27, 2019, 12:23:59 am »
I get:
Code: [Select]
....raised exception class.
Debugger stopped with reason: signal SIGABRT
That debugger error. Not fpc error. Not know precise..... again try run no debugger ?

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #8 on: March 27, 2019, 12:24:30 am »
then it crashes
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #9 on: March 27, 2019, 12:25:58 am »
I tried it without the file by simply the following code
Code: Pascal  [Select][+][-]
  1.   s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=52600');
  2.   if s <> '' then begin
  3.     Memo_Test.Clear;
  4.     extractor := THTMLTextExtractor.Create;
  5.     try
  6.       s := extractor.ExtractFromHtml(s);
  7.       showmessage (IntToStr(Length(s)));
  8.       Memo_Test.Append(s);
  9.       i := 0;
  10.       i := FindMemoLineNumber (Memo_Test, 'Score A', i+1);
  11.  
  12.  
  13.       ShowMessage (i.ToString);
  14.       ShowMessage (Memo_Test.Lines[i]);
  15.       Memo_Test.SelStart := i;
  16.       Memo_Test.SetFocus;
  17.     finally
  18.       extractor.Free;
  19.     end;
  20.   end;

And still get the same error and/or crash.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

zulof

  • Newbie
  • Posts: 4
Re: crashing app when url is changed
« Reply #10 on: March 27, 2019, 12:34:34 am »
Just a long shot, but once upon a time I had some problems with something like this when TMemo.WordWarp was set to true..but probably not..

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #11 on: March 27, 2019, 12:39:19 am »
It doesn't matter if it is set to false or true. Still a crash.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: crashing app when url is changed
« Reply #12 on: March 27, 2019, 12:40:48 am »
I tried it without the file by simply the following code
make little better code:
Code: Pascal  [Select][+][-]
  1.   s := TFPHTTPClient.SimpleGet('https://www.nijb.nl/nijbsheet.php?GameID=52600');
  2.   if s <> '' then
  3.   begin
  4.     Memo_Test.Clear;
  5.     extractor := THTMLTextExtractor.Create;
  6.     try
  7.       try
  8.         s := extractor.ExtractFromHtml(s);
  9.         showmessage (IntToStr(Length(s)));
  10.         Memo_Test.Append(s);
  11.         i := 0;
  12.         i := FindMemoLineNumber (Memo_Test, 'Score A', i+1);
  13.  
  14.  
  15.         ShowMessage (i.ToString);
  16.         ShowMessage (Memo_Test.Lines[i]);
  17.         Memo_Test.SelStart := i;
  18.         Memo_Test.SetFocus;
  19.       except
  20.         on E : Exception do
  21.         begin
  22.           ShowMessage('Exception class name = '+E.ClassName);
  23.           ShowMessage('Exception message = '+E.Message);
  24.         end;
  25.       end;  
  26.     finally
  27.       extractor.Free;
  28.     end;
  29.   end;
  30.  
no run inside lazarus. run outside. want exception see.

madref

  • Hero Member
  • *****
  • Posts: 954
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: crashing app when url is changed
« Reply #13 on: March 27, 2019, 12:58:35 am »
it still crashes because of line number 10
Code: Pascal  [Select][+][-]
  1. Memo_Test.Append(s);
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 3.99 (rev main_3_99-649-ge13451a5ab) FPC 3.3.1 x86_64-darwin-cocoa
Mac OS X Monterey

Thausand

  • Sr. Member
  • ****
  • Posts: 292
Re: crashing app when url is changed
« Reply #14 on: March 27, 2019, 01:09:14 am »
it still crashes because of line number 10
if crash then error very bad. must display exception if not so bad.

sorry, i not know what error  :-[
Quote
Code: Pascal  [Select][+][-]
  1. Memo_Test.Append(s);
have tried
Code: Pascal  [Select][+][-]
  1. Memo_Test.Add(s);
?

same error ?

 

TinyPortal © 2005-2018