Accessviolation when changing Borderstyle

Asked

Viewed 48 times

-1

Hello! I’m trying to change the borderstyle property at the event onCreate form, but error occurs AccessViolation, someone knows how I can solve?

My code:

procedure TfmContasPagar.FormCreate(Sender: TObject);
var
  RedimensionarTela : String;
begin
      RedimensionarTela := TUtil.Sql.SQLLinha('SELECT REDIMENSIONAR_TELA FROM USUARIOS WHERE COD_USUARIO = ' + IntToStr(Codigo_Usuario), Database);
      if RedimensionarTela = 'N' then
         fmContasPagar.BorderStyle := bsSingle
      else
         fmContasPagar.BorderStyle := bsSizeable;
end;
  • Your program has only this functionality?

  • No, but I didn’t think it was necessary to put it all here. The error part is this

  • The Resize screen variable is being declared where? I find it unlikely that the error is in changing Border, unless the scope does not have access to fmContasPagar. Access Violation occurs while trying to access a missing or inaccessible memory address

  • But it is that the screen worked normal, when I went to perform this change the error started to occur

  • Try debugging the code by checking the contents of the variables before and at the time of the error. Keep in mind that Accessviolation occurs due to a missing or improper memory access. Error is not reproducible, which makes it difficult to answer.

  • Debuguei, as the variable is returning 'N', it is in this condition that falls: fmContasPagar.BorderStyle := bsSingle and that’s when the error occurs

  • Utilizes Self.BorderStyle instead of the way you are doing to change the edge

  • I did as you said, avoided the error, but did not execute the command, did not change the borderStyle

  • could you enter the code where you are creating the form Tfmcontaspagar ? The variable fmContasPagar refers to Tfmcontaspagar?

Show 4 more comments

2 answers

0


I did it this way:

procedure TfmContasPagar.FormCreate(Sender: TObject);
var
  RedimensionarTela : String;
begin
      RedimensionarTela := TUtil.Sql.SQLLinha('SELECT REDIMENSIONAR_TELA FROM USUARIOS WHERE COD_USUARIO = ' + IntToStr(Codigo_Usuario), Database);
      if RedimensionarTela = 'N' then
         Self.BorderStyle            := bsNone;
         Self.BorderIcons            := BorderIcons - [biMaximize];
         Self.Constraints.MaxHeight  := 570;
         Self.Constraints.MaxWidth   := 870;
      else
         Self.BorderStyle            := bsSizeable;
         Self.Constraints.MaxHeight  := 0;
         Self.Constraints.MaxWidth   := 0;
end;

0

procedure TfmContasPagar.FormCreate(Sender: TObject);
var
  RedimensionarTela : String;
begin
  RedimensionarTela := TUtil.Sql.SQLLinha('SELECT REDIMENSIONAR_TELA FROM USUARIOS WHERE COD_USUARIO = ' + IntToStr(Codigo_Usuario), Database);
  if RedimensionarTela = 'N' then
  begin
    Self.BorderStyle            := bsNone;
    Self.BorderIcons            := BorderIcons - [biMaximize];
    Self.Constraints.MaxHeight  := 570;
    Self.Constraints.MaxWidth   := 870;
  end
  else
  begin
    Self.BorderStyle            := bsSizeable;
    Self.Constraints.MaxHeight  := 0;
    Self.Constraints.MaxWidth   := 0;
  end;
end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.