Recent

Author Topic: Linked List Class  (Read 27385 times)

Pascaluvr

  • Full Member
  • ***
  • Posts: 216
Re: Linked List Class
« Reply #30 on: March 26, 2012, 03:30:01 pm »


But i hope there is something to be learned or compared from...

There is always something to be learned from another.

Any chance you could put a sample application into a zip file?  I would like to try it.

Best regards
Windows 7, Lazarus 1.0.8, FPC 2.6.2, SQLite 3

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Linked List Class
« Reply #31 on: March 26, 2012, 03:53:12 pm »
Link is still working for me. This message has project attached though.

edit: Quickly rechecking the code, i noticed that there's no error handling in Insert function. Using index value -1 or >=FCount would give SIGSEGV.
« Last Edit: March 26, 2012, 03:56:56 pm by User137 »

Pascaluvr

  • Full Member
  • ***
  • Posts: 216
Re: Linked List Class
« Reply #32 on: March 26, 2012, 04:17:30 pm »
Thanks for the zip.  Unfortunately the code does not compile.

I get:

Identifier not found "RequiredDerivedFormResource"
on this statement:
  RequireDerivedFormResource := True;     

Regards
Windows 7, Lazarus 1.0.8, FPC 2.6.2, SQLite 3

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Linked List Class
« Reply #33 on: March 26, 2012, 04:27:34 pm »
Does it work if you comment it out? My Lazarus is 0.9.31 which is pretty new. The code is there anyway, it's possible to add the code on a new project. I did test compiling the code by putting it on a empty folder.

Pascaluvr

  • Full Member
  • ***
  • Posts: 216
Re: Linked List Class
« Reply #34 on: March 26, 2012, 04:46:39 pm »
Yep, I commented it out and it worked.

Now, lets get back to the part that initiated this discussion.

You suggested that my program could be more efficient by just saving a pointer, rather than copying the data, and I disputed this.

If your program did the following:
 A click on an item in the Listbox displayed the contents of the item - would the current contents of the item be displayed, or would the contents of the item when it was added to the list be displayed?

From my (limited) understanding of your code, it would display the current contents.  The original contents would be lost, (assuming the content changed).

The idea behind my control was to be able to build an 'in memory' database and thus retain the content of all items added.  A click on any item would return the contents of the item at the time it was added - not the contents that it now holds.

Regards
Windows 7, Lazarus 1.0.8, FPC 2.6.2, SQLite 3

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Linked List Class
« Reply #35 on: March 26, 2012, 08:46:51 pm »
If your program did the following:
 A click on an item in the Listbox displayed the contents of the item - would the current contents of the item be displayed, or would the contents of the item when it was added to the list be displayed?
Yes, original contents would remain if you click the item in TListBox. ClassName variable belongs to the same instance of the object, proving its existence in the application memory. For example, i could load a pageload of information to each TStringList, and desktop sized images in the bitmaps. The speed at which TMyList inserts items between them etc would not change.

Either way, i added a little this and that to the project to test what i just mentioned. (It makes content in some of those objects and lets you show it. Also a delete button and corrected Insert procedure). Please download this version:

Pascaluvr

  • Full Member
  • ***
  • Posts: 216
Re: Linked List Class
« Reply #36 on: March 27, 2012, 01:35:37 am »
Thank you so much for that - it has a lot in there that I can learn from.  I still need to get my mind to 'think in objects' and so it will take me a while to fully grasp it, but this example is at a perfect level of complexity for me to learn from.  The simple examples I have seen in tutorials leave me thinking 'great, but whats the point', and more complex ones would have me give up because its too hard.
Windows 7, Lazarus 1.0.8, FPC 2.6.2, SQLite 3

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: Linked List Class
« Reply #37 on: March 27, 2012, 02:15:10 am »
Hi Pascaluvr,

Check out this little 'component designer' app. It let's you build components (or classes by removing certain lines) and was real helpful to me, and still is. It does a lot of the 'skeletal framework' for you. You just define the 'members' in a gui and the 'outline' code is generated for you. You then put your code in between. This was you can code like you are accustomed to and the OO is 'wrapped' around your code. Good to get a feel of the 'framework' part of coding in OO. Also has more advanced features like:

Data Aware/link component creation code generator
Compound Components features for designing 'components within components'
Advanced property editor designer. Make prop editors from your own forms
Integrated Help generator (really cool) your commenting is used to generate an HTML helpfile no extra work.

Nice feature is that you can design your classes/components without Lazarus even running. Open and work with as many instances as you like at once.(Small app only 1 mb)

This was developed in/for Delphi so some features need 'coaxing' to work.

An excellent jump start for OOP, and complex classes/components too.

https://docs.google.com/open?id=0B3cgAqlkzaL0NzcxMmU0ZTAtMGRhZi00NzI4LTgxNjctMjkxNDkwNjMwMzMy
« Last Edit: March 27, 2012, 02:28:38 am by CaptBill »

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: Linked List Class
« Reply #38 on: March 27, 2012, 02:53:03 am »
This is an example of the 'framework' code generated from simply choosing 'file|new' and choosing, from a tree view, the selection 'visual component|can receive focus|TComponent'... all mouse clicks. It basically uses inheritance to build a template for you.

It is a sort of 'Case Tool' for components/classes.

Code: [Select]
{ ****************************************************************** }
{                                                                    }
{   VCL component TMyClass                                           }
{                                                                    }
{   Code generated by Component Create for Delphi                    }
{                                                                    }
{   Generated from untitled component definition                     }
{   on 26 March 2012 at 20:44                                        }
{                                                                    }
{   Copyright © 2012 by ...                                          }
{                                                                    }
{ ****************************************************************** }

unit MyUnit;

interface

uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
     Forms, Graphics;

type
  TMyClass = class(TCustomControl)
    private
      { Private fields of TMyClass }

      { Private methods of TMyClass }
        { Method to set variable and property values and create objects }
        procedure AutoInitialize;
        { Method to free any objects created by AutoInitialize }
        procedure AutoDestroy;

    protected
      { Protected fields of TMyClass }

      { Protected methods of TMyClass }
        procedure Click; override;
        procedure KeyPress(var Key : Char); override;
        procedure Loaded; override;
        procedure Paint; override;

    public
      { Public fields and properties of TMyClass }

      { Public methods of TMyClass }
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;

    published
      { Published properties of TMyClass }
        property OnClick;
        property OnDblClick;
        property OnDragDrop;
        property OnEnter;
        property OnExit;
        property OnKeyDown;
        property OnKeyPress;
        property OnKeyUp;
        property OnMouseDown;
        property OnMouseMove;
        property OnMouseUp;

  end;

procedure Register;

implementation

procedure Register;
begin
     { Register TMyClass with Samples as its
       default page on the Delphi component palette }
     RegisterComponents('Samples', [TMyClass]);
end;

{ Method to set variable and property values and create objects }
procedure TMyClass.AutoInitialize;
begin
end; { of AutoInitialize }

{ Method to free any objects created by AutoInitialize }
procedure TMyClass.AutoDestroy;
begin
     { No objects from AutoInitialize to free }
end; { of AutoDestroy }

{ Override OnClick handler from TCustomControl }
procedure TMyClass.Click;
begin
     { Call method of parent class }
     inherited Click;
end;

{ Override OnKeyPress handler from TCustomControl }
procedure TMyClass.KeyPress(var Key : Char);
begin
     { Call method of parent class }
     inherited KeyPress(Key);
end;

constructor TMyClass.Create(AOwner: TComponent);
begin
     inherited Create(AOwner);
     AutoInitialize;
     
     { Code to perform other tasks when the component is created }
     
end;

destructor TMyClass.Destroy;
begin
     AutoDestroy;
     inherited Destroy;
end;

procedure TMyClass.Loaded;
begin
     inherited Loaded;

     { Perform any component setup that depends on the property
       values having been set }

end;

procedure TMyClass.Paint;
begin
     { Draw the component using the methods supplied by its Canvas
       property (of type TCanvas).  For example: }
     Canvas.Brush.Color := clGreen;
     Canvas.Rectangle(0, 0, Width, Height);
end;


end.

Pascaluvr

  • Full Member
  • ***
  • Posts: 216
Re: Linked List Class
« Reply #39 on: March 27, 2012, 02:54:19 am »
That looks great CaptBill.  I will definitely be playing with that.  Thanks heaps :)
Windows 7, Lazarus 1.0.8, FPC 2.6.2, SQLite 3

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Linked List Class
« Reply #40 on: March 27, 2012, 09:07:45 am »
This is an example of the 'framework' code generated from simply choosing 'file|new' and choosing, from a tree view, the selection 'visual component|can receive focus|TComponent'... all mouse clicks. It basically uses inheritance to build a template for you.

It is a sort of 'Case Tool' for components/classes.

Sounds great. Would the license be compatible with Lazarus and would integration into Lazarus make sense/be feasible?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: Linked List Class
« Reply #41 on: March 27, 2012, 05:59:33 pm »
This is an example of the 'framework' code generated from simply choosing 'file|new' and choosing, from a tree view, the selection 'visual component|can receive focus|TComponent'... all mouse clicks. It basically uses inheritance to build a template for you.

It is a sort of 'Case Tool' for components/classes.

Sounds great. Would the license be compatible with Lazarus and would integration into Lazarus make sense/be feasible?

This would be an excellent addition to the interface would it not? I was thinking to just integrate the same concept into the code explorer would be the way to go. So basically you would only need to have some functionality added that generates code blocks via extra functionality there. The essentials are already in place really in the tools|code templates. So it's a matter of just integrating the code explore with the code templates functionality and structuring things to follow OO rules etc. Really nothing to it.

AS far as liscencing goes, it would be simpler to start from scratch and just get inspiration from this tool. Really there is nothing complex to it. Just string routines manipulating a TSynEdit, TTreeView, and some simple forms. Database integration would be a good feature to add as well.

In fact, this would make an excellent first app for an experienced programmer that wants to learn OO, wouldn't you think? You would be supercharging your learning curve with OO this way, learning it from both directions.

 

TinyPortal © 2005-2018