Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Boolean not assigning in Procedure

Status
Not open for further replies.

tjc240e

Technical User
Nov 12, 2004
133
US
For some reason the RebuildList Boolean in this procedure refuses to run?

I don't rightly understand exactly why but when i debug it, it skips right over the RebuildList lines.

The hints tell me Value Assigned to 'RebuildList' never used, but you can clearly see that i am using the RebuildList in the If statements?

What I am trying to do in a nut shell is when someone picks CommunionList from the ReportTpe List i want to rebuild the AttList to only show the 'Worship Service' AttList. Unless the person already selected 'Worship Service' from the list, then i do not want to rebuild the list (Thus the RebuildList boolean). The AttList is pregenerated when the form is loaded.

Anyone have any ideas?

Code:
procedure TAttendanceOptionsFrm.ReportTypeClick(Sender: TObject);
var
  RebuildList: Boolean;
  EventType: TEventTypes;
  wsName, xName: string;
begin
  SetDefaultDatePicker(True);  //Turn on Date Picker
  GetReportImage(ReportTypes.ItemIndex);  //Get Report Types
  EventType :=PData(Attlist.selected.Data)^.Event_Tpe;  //Retrieve EventType
  ReportTpe := TReportTypes(ReportTypes.ItemIndex);  //Retrieve ReportTpe

  if (ReportTpe = CommunionList) and (EventType <> WorshipService) and RebuildList then begin
    RebuildList := False;
    AttList.items.Clear;
    AttList.ReadOnly:=True;
    wsName:='Worship Service';
    xName:='WORSHIP';
    AttendUnit.MakeTheTree(wsName, xName); //Make Worship list only
    end
  ELSE Begin
    if NOT RebuildList then begin
      AttList.items.Clear;
      AttendUnit.BuildEventOptions;  //Rebuild full list
      RebuildList := True;
      end
  END;
  SetReportTypes;    //Sets up the options available based on report you selected

  if ReportTpe = Averages then
  begin
    SetDefaultDatePicker(False);
  end;
end;
 

The first and only time you use RebuildList it is still uninitialized.

Do you have a global (or form-level) variable with the name "RebuildList?" Try removing the local declaration so that the global/form-level variable will be accessed instead of being over-ridden (scoping problem).

Or, do you have a function somewhere else in your code with the name "RebuildList?" Try using a different name for the local variable.

 
RebuidList was a local variable to the ReportTypeClick procedure. I've tried changing the name to a couple different things and it does the same thing when i break right before it and run it i see my break line in red then the next line it rebuildlist and it skips it. You know how the dots appear before the lines it runs well there is no line before the rebuildlist. I changed the name to MyNewList, CreatedNewList, xRebuildList, and finally my name tjcusick and it still doesnt set the value to it.

well this is interesting... just on a guess i put the RebuildList: Boolean; up in the Public def and lo-n-behold not it is working. I do not understand it but if it works then it works...

How weird is that?

Thanks Zathras for the help.
 
if (ReportTpe = CommunionList) and (EventType <> WorshipService) and RebuildList then begin
RebuildList := False;
AttList.items.Clear;
AttList.ReadOnly:=True;
wsName:='Worship Service';
xName:='WORSHIP';
AttendUnit.MakeTheTree(wsName, xName); //Make Worship list only
end
ELSE Begin
if NOT RebuildList then begin
AttList.items.Clear;
AttendUnit.BuildEventOptions; //Rebuild full list
RebuildList := True;
end
END;

rebuiltlist isnt needed in this code.

first your checking if RebuildList = true (you havent set it to true but it usually is on creation) then if the other two values dont return true it moves to the else block
then if RebuildList = false (which it wont be because you havent set it to) then set it to true (why when its not used anywhere else)

if buy chance the first if = true true true then your setting RebuildList to False (why when its not used anywhere else)

Aaron
John Mutch Electronics
 
But I only want it to Recreate the Full List if it is needed.

See if someone from the initial list already selected (EventType=WorshipService) then the first part of the If will not ReGenerate, thus we still have a full list.

So if they change the (ReportTpe <> CommunionList), then the second IF will not have to regenerate the full list because we already have it.

That is why I want the RebuildList boolean.

Does that make sense of is my logic off?
 
The point that Aaron was making is that to get to the line
Code:
RebuildList := False
in the first begin/end block then RebuildList must be true, but if it's true then you will not enter the second begin/end block, so you will not get to the if statement that uses the new value.
If RebuildList is not used after this code then obviously the new value assinged to RebuildList is never used, hence Delphi ignores the line, as you have found out.
This is maybe clearer in this cut down version of the code:

Code:
if ... RebuildList then begin
  RebuildList := False;
  ...
  end
ELSE Begin
  if NOT RebuildList then begin
    ...
    RebuildList := True;
    end
END;

I think a key point here is that you have declared it as a local variable, hence it will get initialised every time you enter the procedure. i.e. when you use the procedure a second time the value of RebuildList will have nothing to do with what was assigned to RebuildList the first time throught the procedure. By declaring it as a global variable (as you did by declaring it in the public section of your form) then its value will persist from one time to the next, hence the new value assigned to RebuildList may be used again, so Delphi does not ignore it.
I hope that helps you to understand what's going on here

Steve
 
I do understand, thanks for taking the time to explain it.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top