Forum > Beginners

Access Violation on sample Program

<< < (2/3) > >>

(You can actually delete the overridden destructor for TMyDateTime, and its implementation, since it is useless, but harmless).

Try this. Start a new Lazarus project, and save it and name it appropriately in a new directory. Check that the empty project compiles and displays an empty form OK. Copy dateTimeUnit.pas (or whatever you have called the unit that declares TMyDateTime) to the new project directory.
Add a button and a button OnClick handler, and an OnCreate handler and and OnDestroy handler for the project's main form, and add dateTimeUnit to the uses clause.
Complete the implementations of the handlers as follows:

--- Code: ---unit mainDateTime; // or whatever you have called it

{$mode objfpc}{$H+}


  SysUtils, Forms, Dialogs, StdCtrls,
 dateTimeUnit; // or whatever you called it


  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    myDT: TMyDateTime;

  Form1: TForm1;


{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);

procedure TForm1.FormCreate(Sender: TObject);
  MyDT:= TMyDateTime.Create(Now);

procedure TForm1.FormDestroy(Sender: TObject);


--- End code ---

If that works OK, then add the other buttons and handlers one by one, testing as you go until you have the full project working. Delete the first project, which has something wrong somewhere, but without seeing it we don't know where.

Thanks for your efforts, sadly, howardpc, your suggestion also produced an access violation even after creating an entirely new project. Your solution, Bart, would be fine if I was working in a terminal window. I was attempting to learn the basics of OOP and using buttons, check boxes etc. to port an Access project that I have developed into MYSQL and FPC as a front end. I'll give up on this particular problem for now, as it is not really my primary focus, dates and times are not critical in my projected app. This is just part of my learning curve. I'm sure I'll find many (more "useful") problems to waste your time. Thanks for the assistance, anyway.

Can you recommend any good resources that will give me a solid grounding of FreePascal? My background has been dBase and Clipper, with some VBA in the last 10 years. So, procedural languages are more "logical" to me.

Pretty much all Delphi tutorials will provide insight. Search for "essential pascal" (and -delphi) by Marco Cantu

I realise you're moving on, but my curiosity about the original problem is peeked.  :) Any chance you can post the project?

--- Quote ---(main menu: Project->Publish project, choose a new directory to save the published project in, and then zip the result)
--- End quote ---

--- Quote ---This is just part of my learning curve.
--- End quote ---
As I said, couldn't find anything wrong with your code, so your learning curve is on the right track :)


--- Quote from: LSemmens on July 17, 2014, 03:38:12 pm ---howardpc, your suggestion also produced an access violation even after creating an entirely new project.

--- End quote ---

In that case your present Lazarus installation is badly flawed. Uninstall it and clean and remove the directories that were created.
Then reinstall, and make sure you can successfully compile and run an empty project. No GUI development is possible without a working Lazarus IDE that compiles a bare-bones project to show you an empty resizeable form that has working minimise and close icons.


[0] Message Index

[#] Next page

[*] Previous page

Go to full version