Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread AfterLoad issues...
Thu, Nov 5 2015 7:57 AMPermanent Link

Petter Topp

I've started on a UI that I don't know how to solve in a good way...

Consider the following:

- I have several (8-10 for the moment) DataSets that has a set of common fields (Key, Version, FromDate, ToDate, RegBy, ...).
- For my user interface a have a grid that shows a filtered (using button-dropdown and setting params) set of records from a SQL Union of these tables and fields.
- The user should choose one record and Click "Edit record".
- I would like to find the correct dataset (currently solved by identificator in the Union query),
 and then locate the correct record by using Find (Value of Key field).
- This dataset should then be passed as a parameter to a class that creates the Edit form dynamically.

The issue:

At the Click event, I would need to call LoadRows(ADataSet).
Obviously, I would not now when the various DataSet have loaded and when to proceed.

One way would be to have a common method on the AfterLoad event...

Are there other ways to handle this, or is it a bad model?

Any suggestion appreciated.

Petter
Thu, Nov 5 2015 8:56 AMPermanent Link

Raul

Team Elevate Team Elevate

On 11/5/2015 7:57 AM, Petter Topp wrote:
> At the Click event, I would need to call LoadRows(ADataSet).
> Obviously, I would not now when the various DataSet have loaded and when to proceed.
> One way would be to have a common method on the AfterLoad event...
> Are there other ways to handle this, or is it a bad model?

Not sure i'm understanding this fully but one simple way would be to use
the dataset Tag property to denote it's state - set it to 0  before
calling loadrows and then have a common AfterLoad event update the state
 to say 1 and of course do whatever else. Or use the tag to "know" in
the common afterload that this is the actionable datataset that just
finished loading and you can now open the edit form.

Raul
Thu, Nov 5 2015 2:19 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Petter,

<< One way would be to have a common method on the AfterLoad event... >>

That's what I would do.  The Sender parameter is the dataset being loaded (needs a cast), which is all of the information that you need, correct ?

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jan 27 2016 1:46 AMPermanent Link

Petter Topp

Hi Tim.

What do you mean by (needs a cast)?

Petter


Tim Young [Elevate Software] wrote:

Petter,

<< One way would be to have a common method on the AfterLoad event... >>

That's what I would do.  The Sender parameter is the dataset being loaded (needs a cast), which is all of the information that you need, correct ?

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jan 27 2016 4:53 AMPermanent Link

Michael Dreher

Petter Topp wrote:

 ///  What do you mean by (needs a cast)?

Up-casting form TObject to TDataSet, like this:

procedure TfmMain.dsAfterLoad(Sender: TObject);
var ds : TDataSet;
begin
  ds := TDataSet(Sender);
  // ...
  // ds.AccessToAnyPublicMemberOrFunction
end;

Michael Dreher
Wed, Jan 27 2016 1:52 PMPermanent Link

Alan Questell

Richmond Community College

I really like having a common AfterLoad event and always do something like the following.  I just use the name of the Dataset but you could use the Tag.

procedure TMain.dsAfterLoad(Sender: TOBject);
var
  dsName: string;
  iSemesterCreditHours, iSemesterContactHours: integer;
begin
  if Sender is TDataset then begin
     dsName := TDataset(Sender).Name;
     case dsName of
        'dsAllStudents','dsAdvisees','dsSearchID','dsSearchName':
        begin
           gridStudents.Dataset := nil;
           labelCurrentStudent.Dataset := nil;

           gridStudents.Dataset := TDataset(Sender);
           labelCurrentStudent.Dataset := TDataset(Sender);

           sCurrentStudentID := TDataset(Sender).Columns['StudentID'].AsString;
           UpdatePageData(true);
        end;

        'dsPrefixCourses', 'dsAllCourses':
        begin
           gridCourseList.Dataset := nil;
           gridCourseList.Dataset := TDataset(Sender);
        end;
        'dsAcademicPlansView':
        begin
           gridPlanCourses.Dataset := nil;
           gridPlanCourses.Dataset := TDataset(Sender);
           labelSemesterCourses.Caption := IntToStr(dsAcademicPlansView.RowCount);
           dsAcademicPlansView.First;
           iSemesterCreditHours := 0;
           iSemesterContactHours := 0;
           while not dsAcademicPlansView.Eof do begin
              iSemesterCreditHours := iSemesterCreditHours + StrToInt(dsAcademicPlansView.Columns['CreditHours'].AsString);
              iSemesterContactHours := iSemesterContactHours + StrToInt(dsAcademicPlansView.Columns['ContactHours'].AsString);
              dsAcademicPlansView.Next;
           end;
           labelSemesterHours.Caption := IntToStr(iSemesterCreditHours) + '/' + IntToStr(iSemesterContactHours);
        end;
        'dsAcademicPlans':
        begin
           iSemesterCreditHours := 0;
           iSemesterContactHours := 0;
           while not dsAcademicPlans.Eof do begin
              iSemesterCreditHours := iSemesterCreditHours + StrToInt(dsAcademicPlans.Columns['CreditHours'].AsString);
              iSemesterContactHours := iSemesterContactHours + StrToInt(dsAcademicPlans.Columns['ContactHours'].AsString);
              dsAcademicPlans.Next;
           end;
           labelTotalCourses.Caption := IntToStr(dsAcademicPlans.RowCount);
           labelTotalHours.Caption := IntToStr(iSemesterCreditHours) + '/' + IntToStr(iSemesterContactHours);
        end;
        'dsNoOfSemestersPlanned':
        begin
           iNoOfSemestersPlanned := 0;
           iNoOfSemestersPlanned := dsNoOfSemestersPlanned.Columns['NoOfSemesters'].AsInteger;
           planBuildGrid;
        end;
        'dsAllStudentContacts','dsMyStudentContacts':
        begin
           gridContacts.Dataset := nil;
           gridContacts.Dataset := TDataset(Sender);
        end;
     
        
     end; //case dsName
  end;    //if Sender
end;

Petter Topp wrote:

Hi Tim.

What do you mean by (needs a cast)?

Petter


Tim Young [Elevate Software] wrote:

Petter,

<< One way would be to have a common method on the AfterLoad event... >>

That's what I would do.  The Sender parameter is the dataset being loaded (needs a cast), which is all of the information that you need, correct ?

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Jan 28 2016 1:17 AMPermanent Link

Petter Topp

Thanks Guys this really helped...

Br
Petter
Image