I'm new to Pascal and FastReport. This question can probably be answered without knowledge of FastReport. Pascal is Delphi. FastReport4. Edit: I am using pascal script.
I have a text box accepting an 8 character string as input. Each character should be numeric. I'm attempting to validate each character as numeric. I've tried using the val function...
Procedure Val(S : String; var R: Real; Code : Integer);
begin
end;
procedure thisinputOnChange(Sender: TfrxComponent);
var
S : String;
error : Integer;
R : Real;
begin
S := thisinput.lines.text;
Val (S, R, error);
If error > 0 then
Button2.enabled := False;
end;
I got this code online. The explanation says that the function will return an error with a code greater than zero if the character cannot be converted to an integer. Is that explanation correct? Am I misinterpreting?
Right now I am trying to set a button's enabled property to false if the validation fails. I might change that to a message. For now, I would like to get it to work by setting the button property.
I'm not sure if I should be using the onChange event or another event. I'm also not sure if I need to send the input to the val function in a loop. Like I said, I'm just learning how to use this function.
I am able to validate the length. This code works...
procedure thisinputOnChange(Sender: TfrxComponent);
begin
if length(thisinput.lines.text) = 8 then
Button2.enabled := True;
end;
Any suggestions? Should I use the val function or something else? Let me know if I need to provide more info. I might not be able to check back until later, though. Thanks for any help.
Valis a runtime library function (in theSystemunit in both Delphi and Lazarus; it's not something you implement yourself. (Your implementation does nothing at all, BTW.) Shouldn't you be validating the data before it ever gets to FastReport? FR is a reporting engine; I'm not sure why you'd expect to be using it to get input or trying to validate things there.procedure thisinputOnChange(Sender: TfrxComponent);. Is that a form method, ie should it really beprocedure **TForm1.**thisinputOnChange(Sender: TfrxComponent);? Can you show your full/real code please? The mixup with Delphi or Pascal is confusing too - are you using Delphi (and which version) or Turbo Pascal or Lazarus / Free Pascal? Finally, why are you defining your own empty version ofVal? As Ken says it won't do anything! You should use the realVal("Going by your response, I cannot use the Val function" is not what Ken meant.)