RTC Forums

Subscription => Support => Topic started by: Dany on September 09, 2015, 03:09:49 PM



Title: TRtcParse.HasValue[index:string]
Post by: Dany on September 09, 2015, 03:09:49 PM
Almost the same as for TRtcHttpValues the parser would benefit from a neat and performance tuned property/function to find out if a value is present at all IMHO.


Title: Re: TRtcParse.HasValue[index:string]
Post by: D.Tkalcec (RTC) on September 09, 2015, 03:50:24 PM
In the TRtcParser class, the Value[] property returning an empty string means that a value has not been assigned to a variable.

Best Regards,
Danijel Tkalcec


Title: Re: TRtcParse.HasValue[index:string]
Post by: D.Tkalcec (RTC) on September 09, 2015, 06:04:39 PM
Anyway ... I've added the "HasValue" property to the TRtcParse class in RTC SDK v7.00 (just uploaded).

Best Regards,
Danijel Tkalcec


Title: Re: TRtcParse.HasValue[index:string]
Post by: Dany on September 10, 2015, 10:02:37 AM
Maybe i posted too fast, i want the function in order to find out if the placeholder exists in the template that i just loaded into the parser. This in order to be able to skip costly processing. I made a helper class that does the job it looks like this and it's here just for clarification.

Code:
type TRtcParseHack = class(TRtcParse) end;
function TRtcParseCheck.HasVariable(const Index: string): boolean;
var
  idx: integer;
begin
    // return the presence of variable named 'Index'
  if Assigned(TRtcParseHack(Self).FVariables) then
  begin
    idx := TRtcParseHack(Self).FVariables.IndexOf(UpperCase(Trim(Index)));
    Result := (idx >= 0) and Assigned(TRtcParseHack(Self).FVariables.Objects[idx]);
  end
  else
    Result := false;
end;

All good,

/Dany


Title: Re: TRtcParse.HasValue[index:string]
Post by: D.Tkalcec (RTC) on September 10, 2015, 11:03:00 AM
This is actually what the "HasValue" property now does. Here is the implementation for the new "HasValue" property on TRtcParse class in RTC SDK v7.00, which is (as you can see) quite similar to what you did in your "hack class":
Code:
 // return TRUE if a value is assigned to variable named 'Index'
  if Assigned(FVariables) then
    begin
    idx := FVariables.IndexOf(UpperCase(Trim(Index)));
    if (idx >= 0) and Assigned(FVariables.Objects[idx]) then
      Result := True
    else
      Result := False;
    end
  else
    Result := False;

Best Regards,
Danijel Tkalcec