You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's already a ResIDToStr function. It's inverse would be useful if, when presented with a suitably formatted string it could be converted back to a resource ID.
Parsing rules:
If string starts with # and rest is numeric, then the resource ID is numeric and can be created with MakeIntResource.
Otherwise resource ID is just a Pointer to the string itself, which should be OK providing the string passed as parameter remains in scope.
The text was updated successfully, but these errors were encountered:
functionIsValidResIDStr(Str: string): Boolean;
begin
Result := False;
if Length(Str) = 0then
Exit;
if Str[1] = '#'thenbeginif Length(Str) = 1then
Exit;
forvar I := 2to Length(Str) dobeginifnot TCharacter.IsNumeric(Str[I]) then
Exit;
end;
Result := True;
endelse
Result := True;
end;
functionStrToResID(Str: string): PChar;
beginifnot IsValidResIDStr(Str) then
raise Exception.Create('...');
if Str[1] = '#'thenbeginvar NStr := RightStr(Str, Length(Str) - 1);
var N := StrToInt(NStr);
Result := MakeIntResource(N);
endelse
Result := PChar(Str);
end;
Notice how the code is much clearer with function IsValidResIDStr defined, without too much code being run twice. We might as well make that routine public too.
delphidabbler
changed the title
Implemented a StrToResID function
Implement a StrToResID function
Nov 20, 2022
There's already a ResIDToStr function. It's inverse would be useful if, when presented with a suitably formatted string it could be converted back to a resource ID.
Parsing rules:
The text was updated successfully, but these errors were encountered: