How to avoid System Exception when Runtime Themes are enabled? - delphi

I've just ran over something interesting, enabled runtime themes in Project Options and when a hint is shown on a TDCTree(from old Dream components, similar to TTreeView) and the mouse is moved over another node that should show hint, what I get is:
---------------------------
Debugger Fault Notification
---------------------------
Project DRIVE:\path\to\project\MyApp.exe faulted with message: 'system exception (code 0xc000041d) at 0x73c84cad'. Process Stopped. Use Step or Run to continue.
---------------------------
OK
---------------------------
I believe that the same issue occurs within IDE, whenever I try to hover over items when adding items at design time.
If I disable runtime themes in Project Options, no exception, but it shows the "old style XP hint".
Application by itself raises an exception with Event Name "APPCRASH".
Seen quite a few issues related to "runtime themes", but haven't seen any way to avoid these issues without disabling them.
Operating system: Windows 7 x64
Delphi: 2007 with December 2007 and February 2008 updates installed
UPDATE 1:
One way to avoid the issue is:
Procedure TDCTreeToolTip.DoHideToolTip;
Begin
Inherited;
If FToolTipAdded Then
if FTreeNode <> NIL then // fix
DeleteToolTip(ToolTipID,FTreeNode.TreeView.Handle);
FToolTipAdded:=False;
FTreeNode:=Nil;
End;
in unit "dcntree.pas".
it seems that FTreeNode "somehow" gets NIL-ed before the call to DoHideToolTip, so the "System Exception is raised... it still doesn't explain why only when "Runtime themes are enabled"
I don't have time now to investigate this further, but the "trigger" is found, need to figure out "whom" is pulling it.

It seems that at least for now, only the following workaround can be used:
Procedure TDCTreeToolTip.DoHideToolTip;
Begin
Inherited;
If FToolTipAdded Then
if FTreeNode <> NIL then // fix
DeleteToolTip(ToolTipID,FTreeNode.TreeView.Handle);
FToolTipAdded:=False;
FTreeNode:=Nil;
End;
in unit "dcntree.pas".

Related

Access violation adding a value in TChart Delphi component

I'm trying to use TChart component to export a graph to a bitmap file, but i got to a very odd error.
Everytime i try adding a value to the chart, i call the AddY function from the TLineSeries component passing the value as a parameter. When i try adding small values, the graph behaves completely normal as shown:
The problem happens when i try adding some big value at it's first point, i get an access violation like this:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 00450047 in module 'Project1.exe'. Write of address 022AC000'. Process stopped. Used Step or Run to continue.
And the callstack is completely empty, the only line there is the name of my project, and the highlighted line is the "end" of my dpr file.
As i keep pressing ok other erros pops up:
As i'm not skilled enough with those errors, i didn't manage to debug exactly what's going on, i presume its some sorte of corrupted heap, but i can't seem to find out where, since the code is so simple and the component has it's code hidden because it's a third party component.
The funny part is that if i just click ok until the errors are gone and add another value, it shows normally, as well as adding some small value first, and then a big value (by big i don't know exactly the number, but 2000+ starts happening this)
I isolated the TChart from my main software and build a snippet just to test things out, and here's the simple code i'm running:
procedure TdesktopForm.Button1Click(Sender: TObject);
var
vBMP: TBitmap;
begin
vBMP := TBitmap.Create();
try
config();
c.series[0].AddY(StrToFloat(edit.text));
c.PaintTo(vBMP.Canvas.Handle, 0, 0);
vBMP.SaveToFile('D:\test.bmp');
finally
vBMP.Free();
end;
end;
Where c is my visually added TChart component, edit is just a visual TEdit to manipulate what i'm adding and config is a method to configure visual stuff on the graphic with the following code:
procedure TdesktopForm.config();
begin
c.Height:=200;
c.Width:=200;
c.LeftAxis.LabelsFont.Size:=13;
c.BottomAxis.LabelsFont.Size:=13;
c.MarginBottom:=20;
c.MarginTop:=10;
c.LeftAxis.StartPosition:=10;
c.LeftAxis.EndPosition:=90;
c.BottomAxis.LabelsAngle:=0;
c.BottomAxis.Grid.Color:=clBlack;
c.LeftAxis.Grid.Color:=clBlack;
c.BottomAxis.Ticks.Color:=clBlack;
c.LeftAxis.Ticks.Color:=clBlack;
c.LeftAxis.MinorTicks.Color:=clBlack;
c.BottomAxis.MinorTicks.Color:=clBlack;
c.BottomAxis.LabelsMultiLine:=True;
c.BottomAxis.DateTimeFormat:='DD/MM/AAAA hh:mm:ss';
c.BottomAxis.StartPosition:=10;
c.BottomAxis.EndPosition:=90;
c.View3D:=False;
c.Color:= clWhite;
c.Legend.Visible:=False;
c.Series[0].Marks.Visible:=true;
c.Series[0].Marks.Transparent:=false;
c.Series[0].Marks.Style:= smsValue;
c.Series[0].Marks.Frame.Visible:=True;
c.Series[0].Marks.Frame.Color:=clBlack;
c.Series[0].Marks.BackColor:=clWhite;
c.Series[0].Marks.Font.Size:=12;
c.Series[0].Marks.Font.Color:=clBlack;
end;
If it wasn't strangely enough, all of the tests above was using the "Line series", if i try the same thing with Bar series for example, everything works completely normal, i tried adding some absurd values like 999999999 and no errors were raised.
All of the above was using Delphi 5, as my main software is built on Delphi 5.
Does anyone have an idea of what's going on?

XE6 ClientDataSet AV attempting to load data from Firebird

I have a minimalist project with FireDac FDConnection & FDSqlQuery,
DataSetProvider and ClientDataSet, trying to access the example
Employee.FDB that came with the Firebird 2.5 package I downloaded
from SourceForge today.
Everything is set to the defaults as theycame off the palette apart from the database name in the FDConnection's pop-up Information tab and the FDQuery's Sql, which is set to select * from employee.
The FDQuery opens fine but as soon as I try
to open the CDS, in the IDE or running my app, I get an access violation.
This is all my code:
FDQuery1.Open;
Caption := IntToStr(FDQuery1.RecordCount); // this shows 42 on the form's caption
CDS1.Open; // AV here
So, the FDQuery opens ok but the CDS doesn't.
At run time, the exception occurs here:
function TCustomClientDataSet.CreateDSBase: IDSBase;
begin
CreateDbClientObject(CLSID_DSBase, IDSBase, Result);
Check(Result.SetProp(dspropANSICODEPAGE, DefaultSystemCodePage)); <-- Exception here
Check(Result.SetProp(dspropUTF8METADATA, NativeUInt(True)));
Check(Result.SetProp(dspropUTF8ERRORMSG, NativeUInt(True)));
end;
The exception msg is
Project FBTest1 raised exception class $C0000005 with
message 'access vioaltion at 0x0075d05b: read of address 0x00000000'.
In the IDE I get a similar exception if I try to set Active = True on the CDS,
which the message said occurred in DSnap200.Bpl.
The first time it happened at run-time I had some kind of "Incident Report" pop-up
offering to report it to Embarcadero. First time I've seen that.
If I substitute a SqlConnection and SqlQuery for the FDac components, I get
the same error.
So, I guess my question is, can a CDS be provoked into this behaviour simply by using default property settings for a project as simple as this one, i.e. did I miss a step, or is it likely an EMBA QC thing?
Solved! Thanks to Graymatter's suggestion to try Using MidasLib, I've got
to the bottom of the problem and fixed it so that the app now works using Midas.Dll. I'm posting this as an answer, rather than a comment, firstly because it's a bit too long for that, but, more importantly, the cause was actually rather strange and the solution may assist anyone else who runs into the problem.
First, I tried Using MidasLib, and the app ran fine, w/o the AV that the q is about.
So, reassured that the problem doesn't arise with the current MidasLib code, I went
back to trying to get the app to work with Midas.Dll. I checked the Midas.Dll
versions in the XE6 bin directory and \Windows\SysWOW64, and they were both as I
was expecting, 20.0.16277.1276 dated 16 June 2014.
Tracing into CheckDBlient in DataSnap.DSIntf and observing carefully, the penny
dropped and I realised what was happening:
procedure CheckDbClient(const CLSID: TGUID);
[...]
begin
[...]
if DbClientHandle = 0 then
begin
Size := 256;
SetLength(FileName, Size);
if RegQueryValue(HKEY_CLASSES_ROOT, PChar(Format('CLSID\%s\InProcServer32',
[GUIDToString(CLSID)])), PChar(FileName), Size) = ERROR_SUCCESS then
SetLength(FileName, Size) else
begin
[...]
end;
DbClientHandle := LoadLibrary(PChar(FileName));
This gets the path to Midas.Dll from the InProcServer key in its registration, and this
wasn't pointing to XE6's bin directory or SysWOW64, but to another location that was not
of my creation and which contained a version of Midas.Dll dating from 2007. Oddly, unlike a copy I have of the Dll dating from the D7 era, this Dll does not have version info on its property page but it has a creation date of 9 August 2002 and a file size of 351Kb.
So, once I'd found that, fixing the problem was as simple as renaming that Dll so that
the OS won't load it, and re-registering the version in SysWOW64.
Where the rogue Midas.Dll came from isn't clear, but it certainly arrived since
last week, because it isn't in the back-up I happen to have from last Thursday evening.
The only things I've installed since then are a handful of 3rd-party GUI utilities for
managing/accessing Access, IB and Firebird databases, so the culprit seems to have been
one of them.

FastReport 4.0. "Claas TfrxReport Not Found" exception ( RAD STUDIO XE2 )

Dear Stackoverflow users. I am in dire need for help. I have been struggling with the embedded in the Embarcadero XE2 RAD studio edition of FastReport 4.0. and more specifically I have been getting the same error, over and over again, which is the misterious "Class TfrxReport Not found" error. Below I submit a part of the code that causes the problems
procedure TForm1.buildReport(Sender: TObject);
var
DevicePic, SymbolPic: TfrxPictureView;
TitleEntry, xmlField: TfrxMemoView;
MasterDataBand: TfrxMasterData;
begin
if not ADOConnection1.Connected then
ShowMessage('Cannot build Report! Please, connect to the DB!')
else
try
//this is where the Class Not Found Exception is Thrown
frxReport1.LoadFromFile('LibreportTemplate.fr3',True);
// frxReport1.LoadFromFile('helloInfineonThree.fr3',True);
if (frxDBDataset1 = nil) then frxDBDataset1 := TfrxDBDataset.Create(Self);
// connect the report to the DATA
frxDBDataset1.DataSource := DataSource1;
frxReport1.DataSet := frxDBDataset1;
except
ShowMessage('Error has Occured! Report Template File Not Found!');
// exit from this procedure!
Exit;
end;
// If no errors have occured, go on building ur report by actually filling it up with data!
// attach dataSet to the masterdata band of the report.
MasterDataBand := frxReport1.FindObject('MasterData1') as TfrxMasterData;
MasterDataBand.DataSet := frxDBDataset1;
// prepare textfields
TitleEntry := frxReport1.FindObject('TitleEntry') as TfrxMemoView;
TitleEntry.DataSet := frxDBDataset1;
TitleEntry.DataField := 'LibFName';
xmlField := frxReport1.FindObject('xmlField') as TfrxMemoView;
// stretch the field if text too big.
xmlField.StretchMode := TfrxStretchMode.smActualHeight;
//get the XML DATA FROM THE DB.
xmlField.DataSet := frxDBDataset1;
xmlField.DataField := 'LibFXML';
// prepare images
DevicePic := frxReport1.FindObject('ImageEntry') as TfrxPictureView;
DevicePic.DataSet := frxDBDataset1;
DevicePic.DataField := 'LIBFIMAGE';
SymbolPic := frxReport1.FindObject('SymbolEntry') as TfrxPictureView;
SymbolPic.DataSet := frxDBDataset1;
SymbolPic.DataField := 'LibFSymbol';
// build and display report
frxReport1.PrepareReport();
frxReport1.ShowPreparedReport;
end;
When building and running the program, I get the following error message "Cannot Find class TfrxReport" and in DebugMode I get the following warning:
Project "MyProject.exe" raised exception class EClassNotFound with message 'Class TfrxReport not Found'.
As commented in the code above, the exception in question is thrown when executing the frxReport1.LoadFromFile('LibreportTemplate.fr3',True); command.
I tried many different approaches for solving the problem, including searching online for a solution. Here is what I did:
Manually create and destroy the frxReport1 object during Form OnCreate and OnClose - ERROR PERSISTS
As suggested in the FastReport ( I couldnt post the link on SO, cause of "Sorry, posts can't contain that content." error) forum thread, replace files in the FastReport 4\LibD16 folder. - ERROR PERSISTS
Recompile FastReport 4 RAD STUDIO 32 bit Version - ERROR PERSISTS
Recompile FastReport 4 RAD STUDIO 64 bit Version - ERROR PERSISTS
Reinstall Embarcadero RAD Studio and FastReport 4 - ERROR PERSISTS
ASK QUESTION IN STACKOVERFLOW - ????
From the thread in the fast-reports forum, it seems that the problem and the respective solution should be ( I QUOTE) :
This error causes by GroupDescendentsWith(TfrxReport, TControl); code.
This code hides TfrxReport from FierMonkey and for some reason
"FindClass" function can't find for TfrxReport class when you're
loading report(only in IDE). If you can't load report or get similar
error with "Couldn't find TfrxReport" message, put this "Link to Files"
files to "Fast
Report\LibD16" dir (replace all).
However the suggested approach DOES not Solve the problem! What should I do? Does anyone have any idea?
I've face this issue as well and I've solved it doing this,
Create a new ProjectGroup and add DPK's suitable for your delphi version (I use XE6).
You'll see the BPL's will divide into runtime and design.
Start compiling runtime fsX (X means version), fqbX, and so on. If you make a mistake in the order you will notice.
Some package need the search path $(BSDCOMMONDIR)/DCP to be added
Compile and install design packages and you'll see the TfrxReport.
You won't see results once design package is installed, I've restarted the IDE and it goes great ;)
With 2 years delay, I hope this could help!
not sure if you got your answer to this question or not... but I was having the same issue in Rad Studio XE4, using Fast Reports 4.0 Pro.
I had placed my report in a data module, which I could create / destroy when needed, and the datasets were found in there as well. I could place a BarCode element in the report designer, however, when running the application, I would get "Cannot find class TfrxBarCodeView".
After a search of the Source folder found in C:\Program Files (X86)\Fast Reports\source\ I opened a source file called frxBarcode.pas which contained the creation of the class "TfrxBarCodeView".
I simply added frxBarCode to my uses list, and all worked perfectly!
Just a thought.
Add RegisterClass(TfrxReport); somewhere on program's startup. Or, right before the line that raises the error.
I would start by
1
putting an absolute, full path to the fr3 file, and
place it in the user's document directory,
just to rule out file access issues. Do you have the source code to FastReport?
I know this is old but to somebody it might come useful.
I just run into similar problem. It never occurred to me there is a
component on the palette of Fast Reports called frxReportTableObject.
Just drop it on the form in question.
Adding frxBarCode to uses solved the problem.

Disable exception handling and let windows catch it?

I want to disable the exception catching by Delphi and let Windows catch it - making it produce a window like "AppName crashed. Debug , Send", add this to Application events, create a memory dump and so on.
By default, Delphi catches all the exception in TApplication.Run procedure... How can I avoid that without modifying Forms.pas?
You could add an OnException handler that re-raised the exception:
class procedure TMainForm.OnException(Sender: TObject; E: Exception);
begin
raise Exception(AcquireExceptionObject);
end;
initialization
Application.OnException := TMainForm.OnException;
I'm not sure why you would want to do this at all though. It's more normal to use a tool like madExcept or EurekaLog to show an error dialog that yields much more helpful information than the system dialog.
You can set JITEnable to '1' or higher (default is '0'). With '1', non native exceptions, with higher than '1', all exceptions will be handled by JIT or WER (depending on the system).
This may not be what you want though. With this solution any qualifying exception will be passed to the OS, it doesn't matter if they're handled in code or not. Clarification (run outside the debugger):
procedure TForm1.Button1Click(Sender: TObject);
begin
raise EAccessViolation.Create('access denied');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
try
PInteger(0)^ := 0;
except
end;
end;
initialization
JITEnable := 1;
The first example is a native exception, it will be handled by the application exception handling mechanism when JITEnable is 1. But the second example will trigger JIT/WER.
Add your own handler. Application.OnException is probably what you want. Better than leaving it up to windows as well, as you get different behaviours depending on the environment. For instance if windows error reporting is on, it will ask the user if they want to send an error report to MS.
Like Mr Heffernan I recommend you look at something like EurekaLog.
AS. I agree with voices above that this wish is rather strange.
I also agree that practically hooking in TApplication.OnException would probably be enough ("if it looks like a duck...")
However if you truly want to make RTL oblivious to exceptions, there are ways too.
Exception handlers are plugin to low-level RTL, just like heap management, etc.
You can look at KOL (Key Objects Library).
In Delphi 5 times i managed to make 2KB-size DLL.
That required absense of many usualyl taken "for granted" features. Exception were among them.
To enable Exceptions in KOL's system RTL replacement, you had to make some $DEFINE's, and then the code to add exceptions support to IDE was unlocked.
I believe you can still get that modularized RTL version and grep for that $IfDef and see which code is replaced with which.
I believe there is fair chance you can undo that and make Windows avoid calling Delphi RTL over Exceptions.
I don't remember details, but i believe Delphi RTL Exception handler is just registered in Windows core as a callback. And you probably can de-register it (register nil callback).
I believe you can find it in stock RTL, but KOL's modularised RTL would just make it easier to search.

Does TQuery.Unprepare close the query result in Delphi?

I wonder whether in Delphi calling
Query1.Unprepare;
implicitly closes Query1, if it was previously active. Such that e.g. calling Next on it will fail.
You might say, just go ahead and try but I did on a 64-bit Windows 7 system and had all sort of problems with it until finally my BDE Administrator seems to be completely broken. So I decided to just ask this questions before I start to find out, how I can get BDE running on my system ;-)
You can not use Prepare/Unprepare on an open dataset. you need to close it first.
unit DBTables;
...
procedure TQuery.SetPrepared(Value: Boolean);
begin
if Handle <> nil then DatabaseError(SDataSetOpen, Self);
...
// SDataSetOpen = 'Cannot perform this operation on an open dataset';

Resources