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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Would this need to be MDI Forms? 2

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I am re-writing an application I developed (a Jury Management System). This was the first Delphi application and the first "big" application I did. Needless to say the code makes me CRINGE! So, I'm working on version 2, including all the tricks I've found here!

So, I have a process that allows the clerks to update juror information. In the first version a search form opens, the criteria is entered and the information is shown. To see another juror's information, the first Juror Information form is closed and the search form reopens for the next search criteria.

What I'm thinking about doing is allowing multiple Juror Information forms open at the same time. So if the clerk is working on a juror and gets a call about some other juror they can search for the phone call information without closing the juror they are currently working on. Would this be an example of an MDI form? If so, any one know where I can get some good information about MDI forms (how to use them, close them, find open windows, etc.)?

Thanks for any insight!

Leslie
 
Worked like a charm again!!!

Now, another question. A juror may be a public employee, can I open a different form (JurorEmployment) and have the JurorInformation form be the owner of the JurorEmployment form?

Thanks,

leslie
 
Hmmm...the JurorInformation form can create and own the JurorEmployment form but the result may be unpredictable if the JurorEmployment form is another MDIChild. Could the JurorEmployment form be a modal dialog box like a properties window?

Probably, what I would try to do is make the JurorInformation form contain a scrolling region in which you place the content of both forms (Information & Employment) in a vertical layout like a web page and do away with the JurorEmployment form altogether.
 
I'll look into that! Thanks for the info!

Leslie
 
Ok, I'm adding a section to the JurorInformation form to show the public employee information. I have added another query to frmJurorInformation called qryPubEmployees. I want to run a function called GetPubEmpInfo if the field PUBEMP = 'T' in qryJurorInformation. However, when I get to setting qryPubEmployee.Active := True, I get an access violation. Any idea what I'm doing wrong or a different approach?

Thanks
Leslie

Code:
//show JurorSearch form on menu click
procedure TdmJMSMenu.JurorInformation1Click(Sender: TObject);
begin
  frmJurorSearchInfo.Show;
end;

//get search criteria
procedure TfrmJurorSearchInfo.bbtnJSISearchClick(Sender: TObject);
var
i : integer;
strJurorNumber :string;
begin
  for i := 0 to frmJurorSearchInfo.ComponentCount - 1
  do
  begin
    If Components[i] is TEdit Then
      with Components[i] as TEdit do
      begin
        If Text <> '' then
          strJurorNumber := Text;
      end;
  end;
  If not GetJurorInfo(strJurorNumber) then
    MessageDlg('There is no matching juror!', mtInformation, [mbOK], 0);
//clear search criteria for next search
  ClearJSIForm();
end;

function GetJurorInfo(AJurorNumber : string): boolean;
begin
//check if record exists for criteria
  With dmJMS.qryJurorExists do
  begin
    SQL.Clear;
    SQL.Add('SELECT JURNUM FROM JMPMAIN WHERE ');
    If pos('P', AJurorNumber) > 0 then
      SQL.Add('PANLELID = ' + QuotedStr(AJurorNumber))
    else if length(AJurorNumber) = 9 then
      SQL.Add('SSN = ' + QuotedStr(AJurorNumber))
    else
      SQL.Add('JURNUM = ' + AJurorNumber);
    Active := True;
//if no record found, return false, close query
    If isempty then
    begin
      Result := False;
      Active := False;
    end
//if record found create JurorInformation Form
    else begin
      With TfrmJurorInformation.Create(frmMain) do
      begin
        qryJurorInformation.SQL.Clear;
        qryJurorInformation.SQL.Add('SELECT JMPMAIN.*, ' +
        '(TRIM(FIRSTNAME) || '' '' || TRIM(LASTNAME)) AS FULLNAME, CASE PANELID ' +
        'WHEN '' '' THEN ''NO PANEL ASSIGNED'' ELSE PANELID END AS PANELSTAT ' +
        'FROM JMPMAIN WHERE JURNUM = ' +
        dmJMS.qryJurorExists.FieldByName('JURNUM').AsString);
        qryJurorInformation.Active := True;
        Caption := 'Juror Information ' + qryJurorInformation.FieldByName('FULLNAME').AsString;
//if juror is a public employee, get information
        if qryJurorInformation.FieldByName('PUBEMP').AsString = 'T' then
          GetPubEmpInfo(qryJurorInformation.FieldByName('JURNUM').AsString)
        else
          panPubEmp.Visible := False;
        Show;
      end;
      Result := True;
    end;
  end;
end;

function GetPubEmpInfo(AJurorNumber : string): boolean;
begin
//ACCESS VIOLATION HERE!!
  With frmJurorInformation.qryPubEmployees do
  begin
    SQL.Clear;
    SQL.Add('SELECT * FROM JMPPEMPLE WHERE JURNUM = ' + AJurorNumber);
    Active := True
  end;
end;
 
I have it in a Unit (JurorSubs) that is used by frmJurorInformation. If I put it into frmJurorInformation do you think it will work?

les
 
Yes. This problem is a result of changing the code that creates the JurorInformation form to use the With clause. You no longer have the variable frmJurorInformation to reference outside of the with clause.

Placing the code on the JurorInformation form will work as long as you declare the function in the Public section and change the line of code from:
Code:
With frmJurorInformation.qryPubEmployees do
to:
Code:
With qryPubEmployees do
HTH, Dave
 
I had problems getting the public function to work properly. Here's what I ended up with and it seems to be ok. This is in the JurorInformation OnShow Event:
Code:
if qryJurorInformation.FieldByName('PUBEMP').AsString = 'T' then
  begin
    With Self.qryPubEmployees do
    begin
      SQL.Clear;
      SQL.Add('SELECT * FROM JMPPEMPLE WHERE JURNUM = ' + qryJurorInformation.FieldByName('JURNUM').AsString);
      Active := True
    end;
  end;

Will I run into any problems with this setup?

Thanks
les
 
Nope. In my view, that is preferable to using a public procedure because it decreases dependencies between forms. (Now the calling form doesn't need to &quot;know&quot; about this routine in the child form -- like with people, its always better if the MDI children can take care of themselves!)

Good job.
 
Thanks for your help! My users are thrilled that they're getting a version 2 and love the multiple windows!

Leslie
 
Ok, I may have screwed it all up!!!

I switched the JurorInformation form to a MDI Child (just to see the difference in where the forms appeared). All i did was switch it to MDIChild, ran it one time, and changed it back! Now I get an access violation before the JurorInformation form opens, but then it opens with the information.

Any clue on what I did and how to make it go away?

Leslie
 
Probably you placed some code in the JurorInformation form's OnShow or OnActivate events that is trying to reference an object that is not in its uses clause.
 
Dave,

Wanted to let you know that I got all this worked out. My program is coming along nicely (I've used these techniques in A LOT of places!) and I've even learned MORE new stuff to use! Thanks again for all your help on this.

Have a new baby yet?

Les
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top