Recent

Recent Posts

Pages: [1] 2 3 ... 10
1
General / Re: StringReplace
« Last post by Bart on Today at 05:12:39 pm »
So use Trim(Reserved[ i ]) then.

Bart
2
General / crashing app when url is changed
« Last post by madref on Today at 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
3
General / Re: StringReplace
« Last post by furious programming on Today at 05:05:15 pm »
Look at this file — there are trailing white characters, from the case to the very end (look at the attachment). Delete these characters and the code will work as you expect.
4
General / Re: StringReplace
« Last post by Bart on Today at 05:01:27 pm »
Maybe, try to call AdjustLineBreaks() on the text and see if that helps.

Bart
5
General / Re: StringReplace
« Last post by segfault on Today at 04:48:46 pm »
Here's some code which does the same thing except it prompts you to enter a string from the console. I've included the hard-coded array which is commented out.

Code: Pascal  [Select]
  1. USES sysutils;
  2. {CONST
  3.   reserved : ARRAY[1..53] OF string = (
  4. 'absolute',
  5. 'and',
  6. 'array',
  7. 'asm',
  8. 'begin',
  9. 'case',
  10. 'const',
  11. 'constructor',
  12. 'destructor',
  13. 'div',
  14. 'do',
  15. 'downto',
  16. 'else',
  17. 'end',
  18. 'file',
  19. 'for',
  20. 'function',
  21. 'goto',
  22. 'if',
  23. 'implementation',
  24. 'in',
  25. 'inherited',
  26. 'inline',
  27. 'interface',
  28. 'label',
  29. 'mod',
  30. 'nil',
  31. 'not',
  32. 'object',
  33. 'of',
  34. 'operator',
  35. 'or',
  36. 'packed',
  37. 'procedure',
  38. 'program',
  39. 'record',
  40. 'reintroduce',
  41. 'repeat',
  42. 'self',
  43. 'set',
  44. 'shl',
  45. 'shr',
  46. 'string',
  47. 'then',
  48. 'to',
  49. 'type',
  50. 'unit',
  51. 'until',
  52. 'uses',
  53. 'var',
  54. 'while',
  55. 'with',
  56. 'xor');}
  57.  
  58. VAR
  59.   st  :  string;
  60.   i   :  integer;
  61.   fn  :  text;
  62.   reserved : ARRAY[1..53] OF string;
  63. BEGIN
  64.   // load the file of reserved words into array 'reserved'
  65.   assign(fn, 'reserved.txt');
  66.   reset(fn);
  67.   FOR i := 1 TO 53 DO BEGIN
  68.     readln(fn, st);
  69.     reserved[i] := st;
  70.   END;
  71.   close(fn);
  72.  
  73.   writeln('Input a line of code: ');
  74.   readln(st);
  75.   FOR i := 1 TO 53 DO
  76.     st := StringReplace(st, reserved[i], upcase(reserved[i]), [rfReplaceAll]);
  77.   writeln(st);
  78. END.
  79.  

I've also attached the reserved.txt file. Actually I think the problem might be with the format of the file. I cut and pasted the list of reserved words directly from the FP site so I think there may be an issue with the end-of-line markers.
6
General / Re: Need Combobox with full text search
« Last post by sstvmaster on Today at 04:47:34 pm »
i found an possible solution here: https://stackoverflow.com/questions/6667054/how-can-i-filter-the-contents-of-a-combo-box-based-on-whats-been-typed

i used listing 2.

It works, but there is a leak in funktion "Origin" and the mouse pointer disappears while typing.
I don't know how to solve the problems.

Please help, greetings Maik
7
OpenGL / Re: What's wrong ?
« Last post by howardpc on Today at 04:34:37 pm »
Creating the component through its constructor with the right owner will also set the parent correctly in well written code.
This is exactly how the designer inserts controls in a parent control and it should not be necessary to set the parent.
This is nonsense, and irrelevant nonsense.
The OP's question was related not to how the Lazarus designer sets a Parent, but how controls such as TOpenGLControl and TOpenGLCube are parented when -- as here -- they are created in code. In the example only the Parents of the two panels have been set automatically by the Lazarus designer, and that is not the issue.

Creating a component with the right Owner is unrelated to setting its Parent. Hordes of components are non-visual and have no Parent. Even visual components descending from TControl that require a Parent for correct display should not routinely have their Parent set in their constructor (even if there are circumstances where that is an acceptable course of action). What about an on-the-fly control instantiated temporarily with a Nil Owner? You won't get very far equating its Parent with its Owner!
Set a control's Parent in its constructor if you must. But there is no requirement to do so, and this may be impossible if the Parent has not yet been created.
8
General / Re: How to write a license plate recognition program?
« Last post by schuler on Today at 04:17:55 pm »
@Thaddy
I've never run a benchmark against OpenCV. Thank you for bringing to my attention. I'll try eventually.

@Max,
mw108 created a MNIST example here (it identifies numbers - not exactly what you need but it's similar):
https://bitbucket.org/108bits/cai-implementations/commits/branch/master
https://forum.lazarus.freepascal.org/index.php?topic=18769.45

More about MNIST:
https://en.wikipedia.org/wiki/MNIST_database
9
Apologies - I'm away from an IDE right now, so can't give exact steps.  Somewhere on the TListView there is a HideSelection option - either on the TListView, or in TListView.Options.  Ensure this is set to false.
10
General / Re: StringReplace
« Last post by Mike.Cornflake on Today at 03:57:14 pm »
Don't think the problem is with StringReplace (because you prove that works yourself by hardcoding your array).  It's likely in your code that loads reserved.  Can you show us that code instead?
Pages: [1] 2 3 ... 10