The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,513 other followers

Archive for January 28th, 2021

Nick Craver on Twitter: “1. “Are you ready to work on the auth code?” 2. New dev: “Hell yeah, bring it on!” 3.… “

Posted by jpluimers on 2021/01/28

[WayBack] Nick Craver on Twitter: “1. “Are you ready to work on the auth code?” 2. New dev: “Hell yeah, bring it on!” 3.… “.

Relevant because security often is a nightmare:

 

Both threads are a good read.

–jeroen

Read the rest of this entry »

Posted in .NET, Android, Development, Fun, Mobile Development, Software Development, Xamarin Studio | Leave a Comment »

Deciphering the Messages of Apple’s T2 Coprocessor | Duo Security

Posted by jpluimers on 2021/01/28

Interesting read: [WayBack] Deciphering the Messages of Apple’s T2 Coprocessor | Duo Security.

Via:

–jeroen

Posted in Development, Security, Software Development | Leave a Comment »

Delphi: getting the name of the current unit

Posted by jpluimers on 2021/01/28

If you have a class (like TMyClass) in the current unit, you can get the unit name as follows:

  • inside a method of the class (either instance or class method): call UnitName or UnitScope to get the unit name
  • outside a method of the class: call TMyClass.UnitName or TMyClass.UnitScope

Delphi added UnitName [WayBack] and  Delphi XE2 added UnitScope [Archive.is]. Their implementations are different, but I have not seen classes where the outcome is different.

The code below shows that when the underlying RTTI UnitName field inside a PTypeData referred by a PTypeInfo contains an @ sign, then UnitName takes the part before the @, and UnitScope the part after the @, but I have not yet seen units where the underlying field contains an @ sign.

If you have seen that, please let me know.

I needed this in order to research some unit initialisation order issues.

A post helpful with that was [WayBack] windows – Can I determine the order in which my units have been initialized? – Stack Overflow for which this comment by Ritsaert Hornstra is the most important bit:

Related: If you use a unit in the interface section you know that that unit will be initialized BEFORE the unit that uses that unit. When using units in the implementation section this is not the case. So usually when you are using a unit with a singleton in it, created in it’s initialization section, you should use that unit in the interface section to make sure that it is initialized before use.

There is also an answer [WayBack] by Remko Weijnen that shows how to hack the current initialisation order if you know the address of InitContext inside the System.InitUnits method.

Back to UnitName versus UnitScope, the code:

class function TObject.UnitName: string;
var
  LClassInfo: Pointer;
  S: _PShortStr;
begin
  LClassInfo := ClassInfo;
  if LClassInfo <> nil then
  begin
    S := @PClassData(PByte(LClassInfo) + 2 + PByte(PByte(LClassInfo) + 1)^).UnitName;
    if S^[1] <> '@' then
      Result := UTF8ToString(S^)
    else
      Result := UTF8ToString(Copy(S^, Pos(_ShortStr(':'), S^) + 1, MaxInt));
  end else
    Result := '';
end;

class function TObject.UnitScope: string;
var
  LClassInfo: Pointer;
  S: _PShortStr;
begin
  LClassInfo := ClassInfo;
  if LClassInfo <> nil then
  begin
    S := @PClassData(PByte(LClassInfo) + 2 + PByte(PByte(LClassInfo) + 1)^).UnitName;
    if S^[1] <> '@' then
      Result := UTF8ToString(S^)
    else
      Result := UTF8ToString(Copy(S^, 2, Pos(_ShortStr(':'), S^) - 2));
  end else
    Result := '';
end;

Related:

–jeroen

Posted in Delphi, Development, Software Development | 1 Comment »

 
%d bloggers like this: