Access violation when creating ActiveX control after upgrading to C++Builder 11 - activex

The following code creates an ActiveX component on a hidden form. It works well with C++Builder 10.4, but crashes when compiled with C++Builder 11.0.
container = new TForm((TComponent*)NULL);
container->Visible = false;
softlock = new TCryptoLicense(container); // <= A.V.
softlock->Parent = container;
The Access Violation occurs in the constructor of TControl after CreateTouchManager, when it uses FTouchManager. I have already tried the following things that did not help:
make the form visible
add an Owner to the Form constructor
call HandleNeeded on the container
create it delayed, not in startup of application
Dropping the component unto a form in a new application caused the same exception to occur at design time.

Reimporting the ActiveX control into a new package fixed the problem. Maybe some data from CB10 and CB11 got mixed up.

Related

Delphi TurboPower Async Professional Data Packet Access Violation…

I use windows 7, 64-bit SP1, and TP Async V4.07 and have the following problem:
I have two Com ports, Com11, and Com18.
I add the following components to my form:
I open a Com port on ApdComPort2 (Com18) and it works without a problem. The ApdDataPacket2 detects the packet terminator and the result displayed is what is expected. Both Com11 and Com18 work fine.
Now if I open another Com port (Com11) with ApdComPort1 I get an Access violation:
The code that generates the error is this in the AdPacket module:
procedure TApdDataPacketManager.EnablePackets;
var
i : integer;
begin
for i := 0 to pred(PacketList.Count) do
with TApdDataPacket(PacketList[i]) do
if Enabled then
Enable;
end;
It is the PacketList.Count that seems to be the problem when it iterates through the list but I can’t catch why:
Note that ApdComPort2 works without problem with both Com11 and Com18.
If I remove the Apd2 components then Apd1 works as expected. The problems surface when I try to use two (or more) Apd components at the same time.
Does anybody have a suggestion or can recommend a component that works with more than one serial port simultaneously?
Some notes about the Turbo Power Async Professional components:
When using the Async components it is very important on how you add the components to the form. If you don’t does it in the right order and in the correct way it will not work if you use more than one serial port. You will actually get an access violation. For example, if you add the components below you have to do it in this way:
Add one ApdComPort to the form, it will become ApdComPort1
Now copy and paste this component to the form, it will become ApdComPort2
Add one ApdDataPacket component to the form, it will become ApdDataPacket1
Now copy and paste this component to the form, it will become ApdDataPacket2
Add one ApdSLController component to the form, it will become ApdSLController1
Now copy and paste this component to the form, it will become ApdSLController2
When doing it, as described above, it works to use two serial ports with ApdDatapacket. Now I don’t get any getting Access violations. I have tested it up to 4 ports and it works as well.

Usage ICoreWebView2EnvironmentOptions in C++Builder 11

I am trying to disable CORS in TEdgeBrowser and found a lot of solutions by using ICoreWebView2EnvironmentOptions because TEdgeBrowser is implement by WebView2.
In Microsoft's document, the sample code seems to used for Visual C++ and C++ Builder is not applicable:
auto options = Microsoft::WRL::Make<CoreWebView2ExperimentalEnvironmentOptions>();
Here is the code I have tried in C++ Builder 11:
_di_ICoreWebView2EnvironmentOptions *m_WV2_EnvOpt = new _di_ICoreWebView2EnvironmentOptions();
m_WV2EnvOpt->put_AdditionalBrowserArguments(L"--disable-web-security");
It would fail in m_WV2EnvOpt->put_AdditionalBrowserArguments().
I have no idea and maybe I got the wrong way. Can someone help me?
_di_ICoreWebView2EnvironmentOptions is a typedef for DelphiInterface holding a ICoreWebView2EnvironmentOptions* pointer. You don't use new on DelphiInterface itself, you new a class that implements the interface, eg:
class TCoreWebView2EnvironmentOptionsImpl : public ICoreWebView2EnvironmentOptions
{
// implement IUnknown and ICoreWebView2EnvironmentOptions as needed...
};
_di_ICoreWebView2EnvironmentOptions m_WV2_EnvOpt = new TCoreWebView2EnvironmentOptionsImpl;
However, WRL objects are not used this way.
In this case, the WebView2 library exposes ICoreWebView2EnvironmentOptions as a COM object, so you can use CoCreateInstance() to instantiate it (the CLSID for the WebView2 library is 26D34152-879F-4065-BEA2-3DAA2CFADFB8, and the IID for ICoreWebView2EnvironmentOptions is 2FDE08A8-1E9A-4766-8C05-95A9CEB9D1C5), eg:
_di_ICoreWebView2EnvironmentOptions m_WV2_EnvOpt;
CoCreateInstance(LIBID_WebView2, NULL, CLSCTX_INPROC_SERVER, IID_ICoreWebView2EnvironmentOptions, (LPVOID*)&m_WV2_EnvOpt);
However, that doesn't help you in this situation, because you would have to provide the created ICoreWebView2EnvironmentOptions object when creating the WebView2 object, and AFAIK TEdgeBrowser simply does not allow you to do that.
You could try setting the WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS environment variable before the WebView2 object is created, but AFAIK this method does not support the --disable-web-security option.

How to set alignment in Fire Monkey multi device application at runtime C++ Builder?

The main problem is FMX dose not support the SomeController->Align = alClient; but that code will work in the VLC application, so after many googling, I find TAlignLayout.Client for my case and the documentation of it is here and here, I try many way to use it but it wont work!
I want create Frame in the runtime as you can see in the following code:
TSettings *appSettingsFrame;
appSettingsFrame = new TSettings(viewSettings);
appSettingsFrame->Parent = viewSettings;
appSettingsFrame->Align = TAlignLayout.Client;
TSettings is Fire Monkey Frame and I use the above code in FormCreate event to create it, at runtime.
viewSettings is TMultiView and it's place for appSettingsFrame.
If I run application for Android target, the error massage point me to 'TAlinLayout' dose not refer to a value.
And if I run application for 32-bit Windows target, the error massage point me to Improper use of typedef 'TAlignLayout'.
Hope this will help someone, I did used :: instead of . to fix issue.
TSettings *appSettingsFrame;
appSettingsFrame = new TSettings(viewSettings);
appSettingsFrame->Parent = viewSettings;
appSettingsFrame->Align = TAlignLayout::Client;

How to declare an object in the "Mastering delphi" book

Im learning delphi through books and am encountering a problem in this chapter: http://etutorials.org/Programming/mastering+delphi+7/Part+IV+Delphi+the+Internet+and+a+.NET+Preview/Chapter+19+Internet+Programming+Sockets+and+Indy/Building+Socket+Applications/#toc
It is this peace of code that gives me trouble because i dont know where to write it.
object IdTCPServer1: TIdTCPServer
CommandHandlers = <
item
Command = 'test'
Name = 'TIdCommandHandler0'
ParseParams = False
ReplyNormal.NumericCode = 100
ReplyNormal.Text.Strings = (
'Hello from your Indy Server')
ReplyNormal.TextCode = '100'
end
That is part of a DFM file of a form with a non-visual component called TIdTCPServer on it. Just place such a component on your form and use the property editor to set the properties to the given values. For example, you have to add a command handler (using the CommandHandlers property) and set its Command property to "test".
That is part of the DFM file, which you don't edit directly. I just placed a TIdTCPServer on a form and the DFM shows:
object IdTCPServer1: TIdTCPServer
Bindings = <>
DefaultPort = 0
Left = 80
Top = 112
end
You can see this for yourself if you right click on your form and choose 'View as Text' (or if you inspect the .DFM files in an editor if you have your configuration set to save them as text.
When you start filling in more (non-default) properties of the TIdTCPServer, Delphi will store these in the DFM as well. I don't see a CommandHandlers property in my Delphi version (XE2, Indy 10.5.8.0), but yours has one (in the example).
[Edited to add] I see from your comment on another answer that you do not have a CommandHandlers property for TIdTCPServer either, this may indicate that the book author used a different Indy version than you do. You can see your version by right-clicking on any Indy component on the form.
CommandHandlers are indeed old. Googling "tidtcpserver commandhandlers" leads to e.g. "The CommandHandlers collection was moved to a new TIdCmdTCPServer component in Indy 10." That makes me suspect you have Indy 10 and the book references 9. You'll have to find Indy 10 examples for what you want to do. That should not be too difficult.

Cannot perform this operation on a closed dataset: Delphi XE4 error with Firebird 2.5.2

I have following code in Delphi 7 as well as in Delphi XE4. I am migrating my code from Delphi 7 to Delphi XE4. I am dealing with datasets.
My dataset dsABC is declared like following:
TfrmMainForm = class(TForm)
dsABC: TpFIBDataSet;
......
......
end
dsABC is used like following at many places:
1. if (dsABC .Locate('ID', Id, [])) then ---File 1
2. dsABC.Edit ----File 2
I mean to say, wherever it is used, its throwing this above said error in Delphi XE4 but same is working fine in Delphi 7.
But if I write following line before using dataset, it works fine
if not(dsABC.Active) then dsABC.Active := True;
I am forced to write this line in each and every file, and for each and every dataset in Delphi XE4 but I wonder then why its working in Delphi 7. Am I doing right to solve my problem or I need some default setting somewhere to get rid of this problem?
Is dataset in Delphi 7 by default active and inactive in Delphi XE4 and you have to explicitly activate it in Delphi XE4?
I found these links about this problem on stackoverflow, but nothing seems to be relating with my problem:
How do I solve the "Cannot perform this operation on a closed dataset" with Borland Database Engine and a Delphi application?
Cannot perform this operation on a closed dataset
Given you've previously posted problems with connecting to the database (which would render any datasets left active at design time inactive) I would say that this is the root of your problem and highlights the problem with relying on datasets being activated in this manner in your code.
There are some properties in TpFibDatabase for Designsupport:
DesignDBOptions -> ddoStoreConnected maybe these are set for delphi7 as default and not in Xe4
Dataset was getting close because my transaction timeout was set to 1000 i,e one seconds. That's why dataset was getting closed after every second. I set timeout to zero to get rid of this problem.

Resources