Question

I was creating table during execution, however at the creation of the table, (see my code)

procedure CreateTempTable(pDataBaseName,pSessionName:String);
begin
  //-------create "TempTable" 
  TempTable:=TTable.Create(application);
  With TempTable Do
  begin
    //-------set false in "Active"
    Active := False;
    //-------name of Session
    SessionName:=pSessionName;
    //-------name of DataBase.
    DatabaseName :=pDataBaseName;
    Filtered := True;
    //-------name of table
    TableName := 'TempTabl.DB';
    //-------paradox type
    TableType := ttParadox;
    //-------if the table is already exists
    if TempTable.Exists then
      //-------delete the table
      TempTable.DeleteTable;
    //-------create 2 fields "Field1" & "Field2"
    with FieldDefs do
    begin
      Clear;
      with AddFieldDef do
      begin
        DataType := ftFloat;
        Name := 'Field1';
      end;
      with AddFieldDef do
      begin
        DataType := ftFloat;
        Name:='Field2';
      end;
    end;

    //-------Create table
    CreateTable;  // Here where the exception bursts off
  end;
end;

an exception is raised, which is: "Table is open, Table does not exist". so what is exactly the problem, is it open or doesnot exist?

This is the exception: enter image description here

Was it helpful?

Solution

(inside With TempTable Do) There is no need to delete the TempTabl.DB explicit. Is overwritten by CreateTable anyway.

To test if the table is not being used by other components in the IDE, you can try to delete the file TempTabl.DB.

CreateTempTable is now a function CreateTempTable(pDataBaseName,pSessionName:String):Boolean;
So you can better handle errors.

Tested with delphi 5 and RAD Studio 2007.

function CreateTempTable(pDataBaseName,pSessionName:String):Boolean;
begin
result:=false;
// assume pDataBaseName=directory, or change it 
if FileExists(pDataBaseName+'TempTabl.DB') then begin
   if NOT DeleteFile(pDataBaseName+'TempTabl.DB') then begin
      showMessage('Table opened by another part of the IDE');
      exit;
   end;
end;

TempTable:=TTable.Create(application);
With TempTable Do
begin
Active := False;
SessionName:=pSessionName;
DatabaseName :=pDataBaseName;
//Filtered := True;
TableName := 'TempTabl.DB';
TableType := ttParadox;
with FieldDefs do
begin
  Clear;
  with AddFieldDef do
  begin
    DataType := ftFloat;
    Name := 'Field1';
  end;
  with AddFieldDef do
  begin
    DataType := ftFloat;
    Name:='Field2';
  end;
end;
CreateTable;
result:=true;
end;
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top