DCEF TChromium Memory exception on start up - delphi

Another continuation of my previous question here.
In my previous question the project would not run and I was told that the DLL's that come with the component were simply in the wrong place. I moved them to the areas suggested (The output folder of the project I was working on) and the project did indeed run. However, a new error quickly revealed itself, as soon as TChromium attempts to navigate to any webpage, either through the defaulturl property or by use of the LoadURL procedure, the program throws a memory exception.
In particular the error notice says:
Debugger Fault Notification
Project faulted with message 'access violation at 0x00000000; read of address 0x00000000'
This particular error occurs on the end statement of the procedure that attempts to navigate.
To me this says that something is not being initialized properly, but this is simply a test project with nothing but a TChromium component and a TButton to navigate to 'http://www.google.com' on the form.
Source:
unit Test2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, cefvcl;
type
TForm1 = class(TForm)
Chromium1: TChromium;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Chromium1.Browser.getmainframe.LoadUrl('http://www.google.com');
end;
end.
Considering I can see no forum posts, or questions of this nature on this website I can only assume this is an isolated problem, probably caused by something I myself have done wrong, but for the life of me I cannot think what.
So my question is, does anyone know what is causing this error and have I simply made my project wrong?

Related

An inexplicable error class error in my application

I have a major problem and I have no idea how it might be corrected. Out of the blue, when I compile then try to run my application - which I have been working on for six months - I get a Class Not Registered error. I also have a pop-up error message saying that dbx.dbl was not found. I have added nothing to the program in the past few days which included any new classes. I am using Delphi 5. I do not know how to identify which class is not registered. The program will not run and I have spent hours trying to track down the problem without success.
More information: I have moved the executable and data files to another computer, and it all runs fine. So it seems to be a problem with my development box.
More Information: I did as fpiette suggested but found nothing which helped. So I created a very basic application:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, ADODB;
type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
ADOConnection1.Connected := True;
ADOQuery1.Close;
ADOQuery1.Connection := ADOConnection1;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from tblsupplier');
ADOQuery1.Open;
end;
end.
The Class Not Registered error occurs when it executes the ADOQuery1.Open; line.
Am I right in assuming that since there are no other components in the program that the error must be in the ADO code? The ADOConnection1 points at an Access database called Suppliers and the connection test was successful.

Why I don't receive Exception if I use the object after I destroy it?

The following code works just fine, but it shouldn't ! When I click the Button1, the object is destroyed first, and then its Value is used and I don't receive any Access Violation or something... Even more, the multiply operation gives the correct result, that proves that Obj1 is not destroyed ! But then again, this is not true either, because when I close the program it does'n report any memory leakage. I'm very confused.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
MyObj = class(TObject)
Value: Cardinal;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
public
Obj1:MyObj;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Obj1.Free;
Obj1.Value:=Obj1.Value * 5;
Caption:=IntToStr(Obj1.Value);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown:=true;
Obj1:=MyObj.Create;
Obj1.Value:=10;
end;
end.
The object is destroyed. The memory is returned to the memory manager. What happens next is out of your control. The memory could be returned to the system. In which case you'd see a runtime error. Or, the memory could be kept alive by the memory manager ready to reuse the next time the program asks for a block of that size. This is what happens here.
Your program exhibits undefined behaviour. Anything could happen, including the program appearing to work. Obviously the program is wrong and you must not access objects after they have been destroyed.
If you use the full debug version of FastMM then you should see an error because in that scenario steps are taken to detect access after free. That's a useful debugging tool.

Disable all Run time error messages in Delphi?

what is most standard and simple way to tell a prevent Delphi program to show ANY message windows when user run the exe?
for example this is my program with a web browser object, when site have errors that Geko component showing errors to user... i want to stop it.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, MOZILLACONTROLLib_TLB;
type
TForm1 = class(TForm)
MozillaBrowser1: TMozillaBrowser;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit1;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MozillaBrowser1.Navigate('http://www.xeex.ir');
end;
end.
There's no way to do what you ask in general. You cannot apply a setting that will stop all error dialogs being shown.
For native Delphi exceptions, you can choose to ignore them if you wish. Not that that would be a good idea. For message boxes shown by third party code you need that code to offer a way to suppress those errors. If that mechanism exists, you can of course use it. But if no mechanism exists then you are out of luck. And every different library will use separate mechanisms.

Why don't I get an access violation when I call methods on an uninitialized function result?

One of my coworkers show me a code written in Delphi-XE XE Version 15.0.3953.35171, which I believe it should raise an access violation. The code is bellow:
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm3 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
function test:TstringList;
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.FormCreate(Sender: TObject);
var aStrList : TStringList;
begin
aStrList := TStringList.Create;
test;
FreeAndNil(aStrList);
end;
function TForm3.test: TstringList;
var i:Integer;
begin
for i:=0 to 1000 do
Result.Add('aaa');//AV?
end;
end.
Inspecting aStrList and Result has the following results:
aStrList: TStringList $12FEDC : $42138A
Result: TStringList $12FEC4 : $B01B90
I do not understand why it is working. Result.Add should raise an access violation
LE: It seems that is working only on Debug Build Configuration.
The Result variable in that function has not been initialized and could hold any value. Now, the implementation detail means that, in some combinations of compiler options, your code happens to run with Result referring to a valid object. But that's really just a coincidence of those implementation details.
If this were C++ then that function would exhibit undefined behaviour. Although that term does not have a formal meaning in Delphi, it can be helpful to use that term in a Delphi setting to mean the same thing as in the context of C++.
I would also make the point that even if Result did not refer to a valid string list object, your code would not be guaranteed to raise an access violation. It could be that Result points to a block of memory that just happens to look enough like a string list for that code to execute successfully.
If you do things properly, you can predict the behaviour of your program. If your code is flawed and induces undefined behaviour, then your program's behaviour becomes unpredictable. It may work. It may fail. Or that code may execute fine, but then lead to a failure later in the program's execution. And so on.

DUnit: How to run tests?

How do i run TestCase's from the IDE?
i created a new project, with a single, simple, form:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
end.
Now i'll add a test case to check that pushing Button1 does what it should:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
TestFramework;
type
TForm1Tests = class(TTestCase)
private
f: TForm1;
protected
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestButton1Click;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//todo
end;
{ TForm1Tests }
procedure TForm1Tests.SetUp;
begin
inherited;
f := TForm1.Create(nil);
end;
procedure TForm1Tests.TearDown;
begin
f.Free;
inherited;
end;
procedure TForm1Tests.TestButton1Click;
begin
f.Button1Click(nil);
Self.CheckEqualsString('Hello, world!', f.Caption);
end;
end.
Given what i've done (test code in the GUI project), how do i now trigger a run of the tests? If i push F9 then the form simply appears:
Ideally there would be a button, or menu option, in the IDE saying Run DUnit Tests:
Am i living in a dream-world? A fantasy land, living in a gumdrop house on lollipop lane?
Adding a TestCase to the main project is not the way to go. You should create a separate TestProject (you can have it in the same ProjectGroup as the main project), add a TestCase and run.
I agree with Uwe Raabe, but sometimes it can be useful to have a 'hidden' link within your app to run the DUnit GUI. I use:
TGUITestRunner.runRegisteredTests;
Call this from your button at the DUnit GUI will open for you to manually run and view test output.
For example, if you hold down a special key combination when opening the software's own "Control Panel", you get some advanced entries:
I like the idea of having a 'Run DUnit tests' command in the IDE.
It could be implemented by checking for a DUnit project in the same folder, having the same name as the current project:
Project1.dpr -> the software under test
Project1.Tests.dpr => the DUnit test app
In this case, the IDE should enable the Run DUnit tests command.
After executing the tests, a list of all failed tests should be displayed which allows to jump to the source line where a test failed.
If tests caused memory leaks, a list of all leaks should be displayed which allows to jump to the source line where the memory leak has been created
(DUnit can be configured to detect memory leaks and fail tests when one has been found)

Resources