Posts Tagged ‘Delphi’

Mozilla Firefox ActiveX Control

Wednesday, December 15th, 2010

Well, as I said a few days back, I started on writing a small concept-browser.

First run at it was using TEmbbededWB from bsalsa. IE-based obviously (6.0 in my case). I ran the test project switching tabs and the applications memory kept raising and raising … ok, so we know IE sucks but this is ridiculous.

Then, I rememberd a mozilla project long ago (mozdev) but it seems they’ve gone dead for the past 5 years so … google-ing brought me to : http://www.iol.ie/~locka/mozilla/control.htm

Now, there’s an IEPatch application there that supposidly converts it from using IE to using mozilla. Take it from me, at least with tembeddedwb, it doesn’t work. It will crash like crazy.

Now, after getting everything to work and removing the tembeddedwb stuff (including address bar) and rewriting the test project to suit the new control, things work fine. Well, almost fine because neither TWebBrowser nor TMozillaBrowser support changing the user agent (other than in the navigate method, but once you click on a link in the page, bye-bye). Aside from that, I started doing the memory test. AAAAAAnd it still leaks. Not as ugly as IE but still, about 1 MB per page load.

Ok, so this still suck.

Now, let’s find alternatives. D-Gecko on sourceforge.. dead for 2 years, no release.  TGeckoBrowser on sourceforge (based on d-gecko). dead for a year, one release. Has compilation issues (mainly caused by code used for debug, not ansi compatible (in D7)). After that’s fixed, it will compile and install in the IDE.

then, for whatever reason, they inlcuded the FastMM_FullDebugMode.dll in the project. Uhm … I’m pretty sure that somehow breaks the license of fastmm but that’s another story. The main issue is: did you people never heard of conditional defines?

Loading the first sample app: ChromeWin complains of not being able to find a unit referenced. duuh, improper path on the included pas file. It’s actually in the parent directory. Once that is fixed, an AV is thrown when opening the form.

Well, so much for today.

Conclusion: it all sucks and it’s back to IE. Or the mozilla activex control. at least they’re compatible and if the mozzila activex is less memory leaky than ie, then I’ll stick with it. And maybe fix the leaks too.

Related posts

Using SWbemRefresher in delphi

Monday, February 1st, 2010

Somebody asked me to help him get a working delphi code for SWbemRefresher. I obviously tried the first natural approach of using the WbemScripting_TLB unit but that didn’t work.
So, since I couldn’t get the early binding to work (using the interfaces and such) and since the VBS code from MSDN works (I previously tested it), I went with late binding just as VBS, which obviously worked. here’s the code:

http://msdn.microsoft.com/en-us/library/aa393838%28VS.85%29.aspx

function GetObject(Value: String): IUnknown;
// from russel: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20875677.html
var pUnk: IUnknown;
pmk: IMoniker;
pbc: IBindCtx;
cbEaten: LongInt;
clsid: TGUID;
begin

// Check value to determine if this is a programmatic id or a moniker
if (CLSIDFromProgID(PWideChar(WideString(Value)), clsid) = S_OK) then
begin
// Attempt to get the active object, clear the result on failure
if not(GetActiveObject(clsid, nil, result) = S_OK) then result:=nil;
end
else
begin
// Moniker name
if (CreateBindCtx(0, pbc) = S_OK) then
begin
if (MkParseDisplayName(pbc, StringToOleStr(Value), cbEaten, pmk) = S_OK) then
begin
// Attempt to bind the moniker, clear the result on failure
if not(BindMoniker(pmk, 0, IUnknown, result) = S_OK) then result:=nil;
// Release the moniker
pmk:=nil;
end;
// Release the bind context
pbc:=nil;
end;
end;
end;

procedure getprocesslate;
var objServicesCimv2,
objServicesDefault,
objRefreshableItem1,
objRefreshableItem2,
RefreshableItem,
objRefresher:OleVariant;
i:integer;
begin
// Get namespace connections
objServicesCimv2 := GetObject('winmgmts:root\cimv2');
objServicesDefault := GetObject('winmgmts:root\default');

// Create a refresher object
objRefresher := CreateOleObject('WbemScripting.SWbemRefresher');

// Add a single object (SWbemObjectEx) to the refresher. The "@"
// is used because _CIMOMIdentification is a singleton class- only
// one instance exists. Note that the
// SWbemRefreshableItem.Object property must
// be specified or the SWbemRefresher.Refresh call will fail.

objRefreshableItem1 := objRefresher.Add(objServicesDefault, '__CIMOMIdentification=@').Object;

// Add an enumerator (SWbemObjectSet object)
// to the refresher. Note that the
// SWbemRefreshableItem.ObjectSet property
// must be specified or the SWbemRefresher.Refresh call will fail.
objRefreshableItem2 := objRefresher.AddEnum(objServicesCimv2, 'Win32_Process').ObjectSet;

// Display number of items in refresher and update the data.
ShowMessage('Number of items in refresher = ' +inttostr( objRefresher.Count));
objRefresher.Refresh;

// Iterate through the refresher. SWbemRefreshable
// Item.IsSet checks for whether the item is an enumerator.
for i := 1 to objRefresher.Count do
begin
RefreshableItem:=objRefresher.Item(i);
if RefreshableItem.IsSet then
ShowMessage('Item with index ' + IntToStr(RefreshableItem.Index) +
' is an enumerator containing ' + IntToStr(RefreshableItem.ObjectSet.Count) + ' processes')
else
ShowMessage('Item with index ' + IntToStr(RefreshableItem.Index) +
' is a single object containing WMI version ' + objRefreshableItem1.VersionCurrentlyRunning);
end;
end;

Related posts

False/True is not a valid integer value for field blabla

Sunday, January 10th, 2010

Ok, so you designed a small mysql table with a boolean field which got translated to tinyint(1). You then wrote your query in delphi and populated your querys fields and the field got mapped to a TSmallIntField.
And then, on top of everything, you placed a db-aware checkbox on the form to set that field and now you are getting the error
“False/True is not a valid integer value for field blabla”.

What to do? Well, since delphi won’t map your field to a TBooleanField as it should (since the field is actually an integer), you must do it yourself. So, close the project, open your favorite text editor and modify the dfm and pas files so that those fields are now of type TBooleanField.

Then, right before the form declaration add the following:

TBooleanField=class(DB.TBooleanField)
public
constructor Create(AOwner: TComponent); override;
end;

and in the implementation section

{ TBooleanField }

constructor TBooleanField.Create(AOwner: TComponent);
begin
inherited;
SetDataType(ftSmallint);
end;

If you need this in more then one form, then create a unit, like MySqlBooleanField.pas and then add it to the uses clause AFTER the DB unit.

That’s it, you’re all set.

Related posts