Recent

Author Topic: Invalid Function Call  (Read 18861 times)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Invalid Function Call
« Reply #15 on: August 19, 2018, 11:41:24 pm »
If Owner is responsible for creating and free the object, and Parent is responsible for drawing resizing etc, [...]

Please, remember that I started with "simplifying a lot"; I was just trying to explain the basic difference between Owner and Parent for controls, namely that Owner treats with its controls as components while Parent treats with them as (visual) controls; hence the different descendancy. That's all.

Taaz is right, you shouldn't set the Parent yourself in the constructor; that's the job of the ... let's call it user code, i.e. the code which calls Create.

If anything at all, you may check if Parent is set before executing code that needs one, to prevent raising EInvalidOperation. But how then set properties whose "setter" needs a Parent? One easy way is to change only the property's (private) field and set a sentinel field that you then can use in Parent's setter to finish the process. And I'm sure you can find other ways if you set to it  :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Invalid Function Call
« Reply #16 on: August 20, 2018, 02:44:00 pm »
Trying comply with suggestions from all you clever people.
Not ignoring anyone - simply needs to understand why (at least one reason) for doing things one way instead of another - otherwise I will not be able to remember... ;)

Goal is to create a container, that should be able to show a number of list of labels (or StaticTexts - eventually probably manually drawn, but for learning, label will be fine).
Container should have a scrollbar as part of the component, and Lists a headline(Label or StaticText).


So - decided to start over.
Created a simple descendant from Tpanel, that contains or does nothing else.
Functions as expected.
Programmatically creates a scrollbar in the Loaded procedure
It doesn't show up in editor at design time, and Form doesnt show up, when run - but no errors compiling.
Moved the creation of the ScrollBar to Containers constructor.
The scrollbar now shows up in he designer - the Form still does not show, when the program is run...

Pauses execusion and singlesteps, through call to a couple of methods in other files - application.inc, LazMethodList, win32obj.inc, win32winapi.inc - , and eventually end up in a debug error. (image)

Reloading the project, the Panel component is now shown in editor as an area without grid (no outline, just 4 black resize marking - but clicking anywhere doe not select the component, but the Form, and the reappears...
Component can be selected in the object inspector.

Giving Lazarus a pause for now...

Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Invalid Function Call
« Reply #17 on: August 20, 2018, 02:59:45 pm »
:) Don't be shy, show us the source code.

English is not my native language. Me (and I believe most programmers) communicate better using codes not words.

If you have problem using Lazarus or Pascal, you usually will get answers faster if you show us the code or attach the source code here.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Invalid Function Call
« Reply #18 on: August 20, 2018, 03:20:43 pm »
And maybe you should also draw a sketch of what the component should look like. I cannot imagine what a "container showing a number of lists of labels" is.

Without writing a decicated component I would use a TScrollbox as container (it shows scrollbars when inserted controls are larger than the scrollbox size), and add a TListbox for every "list of labels". But probably I don't understand...

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Invalid Function Call
« Reply #19 on: August 20, 2018, 09:45:20 pm »
Well....

Imagine a panel. Scrollbar to the right.
Top of scrollbar has a margin, same size as headers in the lists (columns) to the left.
The lists to the left - there can be one or as many as needed, by the task at hand - all have a header, telleing what the data in this column is about, and the column consists of labels (at least at this point).
In this way, we have kind of a table, with columns (each list of labels) and rows.

The container, also holds all data shown. in either class or structure - haven't decided yet, but will likely be a collection of some sort of a dedicated class.

Scrolling does not scroll the view, but replaces captions in the labels.
Scrollbar values, indicates with element in the collection of items is shown.

The finished components, will have the ability to use different colors - not only for selection and mouse hovering, but also to higligt to help identify different kinds of data.
Could be a display of filenames, where you have documents in one color, images in anothe movies in a third etc...

Some properties, should be shared from the container as well - like the colors, the margins and heights of the labels.

(So will probaly have a problem with circular references as well - but not getting ahead of myself, seems to be a good ides...)


Code: Pascal  [Select][+][-]
  1. unit ListContainer;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, StdCtrls, ExtCtrls;
  9.  
  10. type
  11.   TListContainer = class(TPanel)
  12.  
  13.   private
  14.     FScroller : TScrollBar;
  15.     FScrTop : integer; // Afstand fra overkant - samme højde som listernes Header
  16.  
  17.   protected
  18.     procedure Loaded; override;
  19.  
  20.   public
  21.     constructor Create(aOwner : TComponent); override;
  22.     procedure SetScrTop(tp : integer);
  23.  
  24.   published
  25.      property ScrTop : integer read FScrTop write SetScrTop default 22;
  26.  
  27.   end;
  28.  
  29.  
  30. implementation
  31.  
  32. constructor TListContainer.Create(aOwner : TComponent);
  33. begin
  34.   inherited Create(aOwner);
  35.   FScroller := TScrollBar.Create(Self);
  36.   with FScroller do begin
  37.     Parent := Self;
  38.     SetSubComponent(true);
  39.     ControlStyle := FScroller.ControlStyle - [csNoDesignSelectable];
  40.           Kind := TScrollBarKind.sbVertical;
  41.     Name := 'Scroller';
  42.     Align := TAlign.alRight;
  43.     Enabled := false;
  44.         end;
  45.   SetScrTop(22);
  46. end;
  47.  
  48. procedure TListContainer.Loaded;
  49. begin
  50. end;
  51.  
  52.  
  53. procedure TListContainer.SetScrTop(tp : integer);
  54. begin
  55.   FScrTop := tp;
  56.   if (Fscroller <> nil) then with FScroller do begin
  57.      BorderSpacing.Top := FScrTop;
  58.      Refresh;
  59.   end;
  60. end;
  61.  
  62. end.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Invalid Function Call
« Reply #20 on: August 20, 2018, 10:36:28 pm »
Would it not be easier to adapt a TStringGrid, or a TDrawGrid, than to roll your own component?

jamie

  • Hero Member
  • *****
  • Posts: 6077
Re: Invalid Function Call
« Reply #21 on: August 20, 2018, 11:29:11 pm »
I think you should be checking the  ControlState property before using code that involves handles from the
OS.

 for example, in Delphi it is not good to be calling code within your code if the csCreatnig flag is set
in the ControlState property..

 Also make sure all sizes and positions of the child controls are set prior to, that is, if you are not streaming
from resource.
The only true wisdom is knowing you know nothing

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Invalid Function Call
« Reply #22 on: August 20, 2018, 11:40:12 pm »
@howardpc:
Maybe.
Part of the goal is to learn from the process.

@jamie
Off hand, II'm not using handles from the OS...
Maybe some of the calls I make are down the line - but then the checking should be done there.
Or maybe I misunderstand....

If I place the creation of the scrollbar in the loaded event (at which time the creation should be done), it is not shown in the IDE. - and the form never shows up when the program is run.

Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Invalid Function Call
« Reply #23 on: August 20, 2018, 11:55:46 pm »
Something is wrong with Lazarus.

Tried a project with a form and a stringgrid.
Didn't run or compile it.
But changed the setting of the Top margin of the scrollbar in my own  component to be called in Loaded, rather than create.
Compiled and installed - just to be sure changes are discovered.
Lazarus comes back, with the string grid, not available on the form, shown only with the area of missing grid dots and the 8 black dots.

And the object inspector is gone ...

This project did not include my own components, or my own package.

Rebuilding Lazarus (Tools Configure ...) does not bring the object inspector back.
« Last Edit: August 20, 2018, 11:59:18 pm by Birger52 »
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Invalid Function Call
« Reply #24 on: August 21, 2018, 12:52:23 am »
Menu "View" > "Object inspector" ?
Or: Menu "Window" > "Center a lost window" > "Object Inspector" ?

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Invalid Function Call
« Reply #25 on: August 21, 2018, 03:06:06 am »
@Birger52

I tested the code you provided. Although it was unfinished but it works as what you wrote.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, StdCtrls, uniListContainer;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.     aListContainer: TListContainer;
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. {$R *.lfm}
  27.  
  28. { TForm1 }
  29.  
  30. procedure TForm1.Button1Click(Sender: TObject);
  31. var
  32.   i: Integer;
  33. begin
  34.   Button1.Enabled := False;
  35.   aListContainer := TListContainer.Create(Self);
  36.   aListContainer.Parent := Self;
  37.   aListContainer.Height := 100;
  38.   aListContainer.Width  := 200;
  39.   aListContainer.Left   := 50;
  40.   aListContainer.Top    := 30;
  41.   for i := 0 to 19 do
  42.     with TLabel.Create(aListContainer) do
  43.     begin
  44.       Parent := aListContainer;
  45.       Left := 10;
  46.       Top:= (i * 20) + 10;
  47.       Caption := 'Hello ' + i.ToString;
  48.     end;
  49. end;
  50.  
  51. end.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Invalid Function Call
« Reply #26 on: August 21, 2018, 12:23:55 pm »
@pw
Yes. Only the "Object inspecter" menu items, were not available ...
A PC reboot brought it back.

@Handoko
It does not here. Form is never shown, when program is run.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Invalid Function Call
« Reply #27 on: August 21, 2018, 12:36:09 pm »
@Handoko
It does not here. Form is never shown, when program is run.

Have you tried the source code I provided in the previous post? You can download the zip file and test it.

Birger52

  • Sr. Member
  • ****
  • Posts: 309
Re: Invalid Function Call
« Reply #28 on: August 21, 2018, 03:01:36 pm »
I do not see, how adding a button to what I already have, should make things function.
I have uninstalled Lazarus for now, evaluating alternatives.
Lazarus 2.0.8 FPC 3.0.4
Win7 64bit
Playing and learning - strictly for my own pleasure.

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Invalid Function Call
« Reply #29 on: August 21, 2018, 05:46:52 pm »
I'm sorry to hear that you didn't find Lazarus is the one that suits you. Lazarus is a nice development tool if willing to spend more time to understand how it works.

People here are nice. If you ever miss Pascal programming, you know you always be welcome here.

 

TinyPortal © 2005-2018