0

this is my code:

  if DRelatiebeheer.ContactpersoonID.Post = Action then
    KJSMDBGrid1.RefreshData;
  KJPanel4.Visible := true;

my question is how can i set the panel on visible when the post is succesfully ended.

I dont know how to fix it, tried many ways but didn't find a solution for the problem.

I think the code doesn't work, because i put it invisible on the OnGetCellParams event.

And I only want to set the last panel visible when the information is posted

procedure TFRelatiebeheer.KJSMDBGrid1GetCellParams(Sender: TObject);
begin
  if DRelatiebeheer.ACCID.AsInteger <= 0 then
    KJPanel3.Visible := false;
    KJPanel4.Visible := false;
  else
  begin
    KJPanel3.Visible := true;
end;

this is my OnGetCellParams event, this is the other

procedure TFRelatiebeheer.SaveCancel(Sender: TObject);
begin
  if (DRelatiebeheer.CID.State in [dsEdit, dsInsert]) then
    DRelatiebeheer.CID.Post;
  DRelatiebeheer.AID.Post;
  if DRelatiebeheer.CID.Post = Action then
    KJSMDBGrid1.RefreshData;
    KJPanel4.Visible := true;
  end;
Daan Kleijngeld
  • 1,375
  • 2
  • 10
  • 13

1 Answers1

2

I think the answer can be found in my first comment to your question. Let's look at this code:

procedure TFRelatiebeheer.SaveCancel(Sender: TObject);
begin
  if (DRelatiebeheer.CID.State in [dsEdit, dsInsert]) then
    DRelatiebeheer.CID.Post;
  DRelatiebeheer.AID.Post;
  if DRelatiebeheer.CID.Post = Action then
    KJSMDBGrid1.RefreshData;
    KJPanel4.Visible := true;
  end;

The indentation is off. You think that you are setting KJPanel4.Visible inside the if, but you are not. Let's correct the indentation:

procedure TFRelatiebeheer.SaveCancel(Sender: TObject);
begin
  if (DRelatiebeheer.CID.State in [dsEdit, dsInsert]) then
    DRelatiebeheer.CID.Post;
  DRelatiebeheer.AID.Post;
  if DRelatiebeheer.CID.Post = Action then
    KJSMDBGrid1.RefreshData;
  KJPanel4.Visible := true;
end;

Do you see what has happened?

Correct this with begin/end:

procedure TFRelatiebeheer.SaveCancel(Sender: TObject);
begin
  if (DRelatiebeheer.CID.State in [dsEdit, dsInsert]) then
    DRelatiebeheer.CID.Post;
  DRelatiebeheer.AID.Post;
  if DRelatiebeheer.CID.Post = Action then
  begin
    KJSMDBGrid1.RefreshData;
    KJPanel4.Visible := true;
  end;
end;

For what it is worth, where I work, our coding standard demands the use of compound statements, with begin/end, and forbids the use of the single statement variant. In the past 15 years since we introduced this rule, we have not once encountered this mistake. Niklas Wirth knew that he had got it wrong and corrected the mistake in Modula-2. But it's simple enough to avoid the problem yourself just by forsaking single statement syntax.


Update, as you and others point out, if DRelatiebeheer.CID.Post = Action then looks dubious. I honestly don't know enough about the classes that you are using to recommend a solution to that problem.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490