Recent

Author Topic: jvvalidator access violation  (Read 139 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 804
    • Blog personal
jvvalidator access violation
« on: September 24, 2024, 04:32:43 pm »
Hello, I trying the Tjvvalidator. I make a small test and when I try to validate I got a access error.
Code: [Select]
function TJvValidators.Validate(const GroupName:string): Boolean;
var
  I: Integer;
  Controls: TList;
  ErrCtrl: TControl;
begin
  Result := True;
  if ValidationSummary <> nil then
    FValidationSummary.BeginUpdate;
  try
    Controls := TList.Create;
    if FErrorIndicator <> nil then
      FErrorIndicator.BeginUpdate;
    try
      { Get all controls that should be validated }
      if FErrorIndicator <> nil then
        for I := 0 to Count - 1 do
        begin
          ErrCtrl := Items[i].ErrorControl;
          if ErrCtrl = nil then
            ErrCtrl := Items[i].ControlToValidate;
          if ErrCtrl <> nil then
            if Controls.IndexOf(ErrCtrl) = -1 then
              Controls.Add(ErrCtrl);
        end;

      for I := 0 to Count - 1 do
      begin
        if Items[I].Enabled and ((Items[I].GroupName = '') or AnsiSameText(GroupName, Items[I].GroupName)) then
        begin
          Items[I].Validate;
          if not Items[I].Valid then
          begin
            if (Items[I].ErrorMessage <> '') and (Items[I].ControlToValidate <> nil) then
            begin
              ErrCtrl := Items[I].ErrorControl;
              if ErrCtrl = nil then
                ErrCtrl := Items[i].ControlToValidate;

              if ValidationSummary <> nil then
                FValidationSummary.AddError(Items[I].ErrorMessage);
              if ErrorIndicator <> nil then
                FErrorIndicator.SetError(ErrCtrl, UTF8Decode(Items[I].ErrorMessage));
              if FErrorIndicator <> nil then
                Controls.Remove(ErrCtrl); { control is not valid }
            end;
            Result := False;
            if not DoValidateFailed(Items[I]) then
              Exit;
          end;
        end;
      end;
      { Clear ErrorIndicators for controls that are valid }
      if FErrorIndicator <> nil then
        for I := 0 to Controls.Count - 1 do
       FErrorIndicator.SetError(TControl(Controls[I]), ''); // clear error indicator. Here I got the error
    finally
      if FErrorIndicator <> nil then
        FErrorIndicator.EndUpdate;
      Controls.Free;
    end;
  finally
    if ValidationSummary <> nil then
      FValidationSummary.EndUpdate;
  end;
end;


I attach the small example.

What am I doing wrong?

Thanks

/BlueIcaro


 

TinyPortal © 2005-2018