#10 Another hook to translate form properties

open-postponed
None
4
2014-07-13
2004-09-03
No

It was discussed in 2003 (Message digest 157, 158 and 164), you
entered it
as an RFE here:
http://sourceforge.net/tracker/index.php?func=detail&aid=808354&group_id=740
86&atid=539911

This missing bits are:

initialization

  ASetStrProp := TypInfo.SetStrProp;
  HookSetStrProp :=THook.Create (pointer(@ASetStrProp),
@TypInfoSetStrProp);
  HookSetStrProp.Enable;

Copy of the code we use:

procedure TypInfoSetStrProp(Instance: TObject; PropInfo:
PPropInfo; const
Value: string);
var
  j: Integer;
  cm: TClassMode;
  ignore: Boolean;
begin
  HookSetStrProp.Reset;
  ignore := False;
  for j := 0 to DefaultInstance.TP_GlobalClassHandling.Count - 1
do
  begin
    cm :=
TClassMode(DefaultInstance.TP_GlobalClassHandling.Items[j]);
    ignore := Instance.InheritsFrom(cm.HClass) and
              ((cm.PropertiesToIgnore.Count = 0) or
(cm.PropertiesToIgnore.IndexOf(PropInfo^.Name) > -1));
    if ignore then
      Break;
  end;
  if ignore then
    TypInfo.SetStrProp(Instance, PropInfo, Value)
  else
    TypInfo.SetStrProp(Instance, PropInfo,
DefaultInstance.gettext(Value));
  HookSetStrProp.Enable;
end;

It's a little dirty because of the need to call the unpatched version
of
SetStrProp in TypInfo, alas the Reset and Enable calls. Well,
THook wasn't
very clean to begin with... ;) There is actually a library (Detours)
that
will hook more cleanly and allow calling the original routine, without
having to patch the code each time. It was presented in The
Delphi Magazine,
Jan 2004 issue 101:
http://www.thedelphimagazine.com/conts/conts101.php

The code can be downloaded here:
http://www.thedelphimagazine.com/disks/dmag101.zip

The drawback is that it will increase the memory footprint and size
of
gettext, but as it is only used during initalization, it shouldn't have
much
to say on runtime behaviour.

Discussion

  • Lars B. Dybdahl

    Lars B. Dybdahl - 2004-09-17
    • priority: 5 --> 4
    • assigned_to: nobody --> dybdahl
    • status: open --> open-postponed
     
  • Lars B. Dybdahl

    Lars B. Dybdahl - 2004-09-17

    Logged In: YES
    user_id=116253

    Postponed, because there needs to be found a solution for
    Delphi .net, too.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks