Board index » delphi » MODIFYALIAS HELP!!!!

MODIFYALIAS HELP!!!!

My app. needs modifications to the Alias during runtime , a typical 'Select
Company' scenario.

This is what I have been trying to do
1. I modify the alias: Session.ModifyAlias(Alias,Stringlist)
2. I make sure all data aware forms are destroyed.
3. I destroy the DATA MODULE (which contains all my tables) :
    Datamodule.free
4. I close the session : Session.Close
5. I create the DATA MODULE again (this causes the session to open again)

PROBLEM:
This procedure works perfectly well when my data aware forms are Modal.
The moment I use nonmodal Forms , the procedure doesn't work , I loose my
connections.

Are there any better ways to modify the existing Alias at runtime?

Regards
Hernus Carelsen

 

Re:MODIFYALIAS HELP!!!!


Hi Harry

you wrote

Quote
> My app. needs modifications to the Alias during runtime , a typical
'Select
> Company' scenario.

I think you can use a TDatabase component, put it on main form and

- Leave AliasName property empty
- Specify DatabaseName property  (this is what you'll use as alias)
- Specify in Params property the path for accessing databases like :

        PATH=C:\myApp\db

NOTE: in DESIGN TIME, if you have a secondary form with a Table (or a
datamodule) you can specify for table's DatabaseName property  the
new alias only if you have open the main form (those with TDatabase
component)

When you need to change 'scenario'  the only thing to do is to change
Params property of the TDatabase component

Have a good time
Ciao :)
Paolo Boscarato

Re:MODIFYALIAS HELP!!!!


Thanx Paolo

I followed your advice , but the same problem occurs: I loose my
connections when my  'data aware forms'  are NonModal.

Re:MODIFYALIAS HELP!!!!


Harry Carelsen wrote

Quote
> I followed your advice , but the same problem occurs: I loose my
> connections when my  'data aware forms'  are NonModal.

Sorry, i've problem with my Internet connections....

I think that solution to your problem is to store tables Active for
the Alias you want to change and to restore (open) after the change
of alias params.

Before you change the 'scenario'  you have to scan the Datasets
property of the TDatabase component and store (in a
TList/TstringList) which datasets are open.
After the change scan the TList and reopen the datasets ... like in
the following code:

procedure TForm1.ChangeCompanyAlias( cNewPath:string);
var
        DataSetList : TList;
        nCtr : integer;
begin
        DatasetList := TList.Create;
        try
             with DatabaseCompany do begin
                for nCtr := 0 to DatasetCount-1 do begin
                        if Datasets[nCtr].active then
                                Dataset.Add( Datasets[nCtr]);
                end;
             end;
             DatabaseCompany.Close;
             DatabaseCompany.Params.Clear;
             DatabaseCompany.Params.Add( cNewPath);
             with DatasetList do begin
                for nCtr := 0 to Count-1 do begin
                        TDBDataSet( Objects[nCtr]).Open;;
                end;
             end;
        finally
             DatasetList.Free;
        end;
end;

Ciao and have good work time
Paolo Boscarato

Other Threads