Forum > Beginners

Access Violation on sample Program

<< < (2/3) > >>

howardpc:
(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+}

interface

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

type

  { TForm1 }

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

var
  Form1: TForm1;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(MyDT.GetDateTimeAsString);
end;

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

procedure TForm1.FormDestroy(Sender: TObject);
begin
  myDT.Free;
end;

end.

--- 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.

LSemmens:
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.

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

Mike.Cornflake:
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 :)

howardpc:

--- 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.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version