RTC Forums
May 02, 2024, 12:12:26 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: TRtcParse.HasValue[index:string]  (Read 3975 times)
Dany
RTC License++
*****
Posts: 69


« 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.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #2 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
Logged
Dany
RTC License++
*****
Posts: 69


« Reply #3 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
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #4 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.