Just how easy is it to restructure a table?

Click on any of the links below to see how easy it is to control the way your tables are restructured. Note that all these examples assume two things:

You should also be aware that changes are written to the table only after a call to Apply method:

Restructure1.Apply;

At any time (before the call to Apply method) you can cancel the changes to the table by placing a call to Cancel method:

Restructure1.Cancel;

How to:

Add a field?

with Restructure1.Field do
begin
  FieldType := pxAlpha; // Paradox Alpha type
  Name := 'NewFieldName';
  Length := 20;
end;
Restructure1.AddField(False); // don't set validity checks

back to top

Change a field?

with Restructure1.Field do
begin
  FieldType := pxNumber; // Paradox Number type
  Name := 'NewFieldName';
end;
// Change the first field and don't change validity checks
Restructure1.ChangeField(1, False);

back to top

Delete a field?

// Drop the third field
Restructure1.DropField(3);

back to top

Insert a field at specific position?

with Restructure1.Field do
begin
  FieldType := pxTimestamp; // Paradox Timestamp type
  Name := 'NewFieldName';
end;
// Insert the field as second and don't change validity checks
Restructure1.InsertField(2, False);

back to top

Move a field?

// Move the second field to the fifth position
Restructure1.MoveField(2, 5);

back to top

Get the field's name, size, type and validity checks (if any)?

// After this call, Restructure1.Field.* and
// Restructure1.ValCheck.* properties are filled
// with all the information about the seventh field
Restructure1.GetFieldDesc(7);

back to top

Access a field by its name?

// FieldByName returns field's position in the table
// You can use this function with all of the above
// method calls. For example:
//
// Restructure1.GetFieldDesc(Restructure1.FieldByName('SomeField'));
//
var
  Position: Integer;

Position := Restructure1.FieldByName('FieldName');
// Note: FieldByName is not case sensitive

back to top

Check if a field has any validity checks?

var
  lVC: Boolean;

lVC := Restructure1.HasValChecks('SomeField');

back to top

Add a validity check?

// Set the default value for a Boolean field
with
Restructure1.ValCheck do
begin
  DefaultValue := 'true';
end;
Restructure1.AddValCheck('SomeLogicalField');

// Set the default value for a Date field, and make it required
with
Restructure1.ValCheck do
begin
  DefaultValue := 'today';
  Required := True;
end;
Restructure1.AddValCheck('SomeDateField');

back to top

Change a validity check?

with Restructure1.ValCheck do
begin
  DefaultValue := '16';
  MinimumValue := '13';
  MaximumValue := '19';
end;
Restructure1.ChangeValCheck('TeenagerAgeField');

back to top

Delete a validity check?

// Remove all validity checks from TeenagerAgeField
Restructure1.DropValCheck('TeenagerAgeField');

// Remove only default value validity check from TeenagerAgeField
Restructure1.GetFieldDesc(Restructure1.FieldByName('TeenagerAgeField'));
Restructure1.ValCheck.DefaultValue := '';
Restructure1.ChangeValCheck('TeenagerAgeField');

back to top

Check if the table has any referential integrity constraints set?

var
  lRI: Boolean;

lRI := Restructure1.HasRefInts;

back to top

Add a referential integrity constraint?

with Restructure1.RefInt do
begin
  MasterTableName := 'MasterTable.DB';
  // Do not allow cascade changes
  // (DeleteOperation is set to urRestrict by default)
  ModifyOperation := urRestrict;
end;
Restructure1.AddRefInt('RefIntName', 'DetailIndexName');

back to top

Remove (delete) a referential integrity constraint?

Restructure1.DropRefInt('RefIntName');

back to top

Add a master password to the table (protect the table)?

Restructure1.AddMasterPassword('NewPassword');

back to top

Change table's master password?

Restructure1.ChangeMasterPassword('NewPassword');

back to top

Remove (delete) table's master password (unprotect the table)?

Restructure1.DropMasterPassword;

back to top

Add an auxiliary password?

// Add a password and set table rights to full
Restructure1.AddAuxPassword('NewAuxiliaryPassword', trFull);

back to top

Change an auxiliary password?

// Change a password and/or change table rights
Restructure1.ChangeAuxPassword('OldAuxiliaryPassword', 'NewAuxiliaryPassword', trModify);

back to top

Remove (delete) an auxiliary password?

Restructure1.DropAuxPassword('ExistingAuxiliaryPassword');

back to top

Set field rights for any specific auxiliary password?

Restructure1.ChangeFieldRights('AuxiliaryPassword', 'FieldName', frReadOnly);

back to top

Add a primary index?

// Set first two fields as primary index
Restructure1.PrimaryIndexFieldCount := 2;

back to top

Remove a primary index?

Restructure1.PrimaryIndexFieldCount := 0;

back to top

Change the number of fields included in primary index?

// Set first four fields as primary index
Restructure1.PrimaryIndexFieldCount := 4;

back to top

I love this stuff! How do I register?

You can register online by visiting this link. Just follow the simple three-step registration process.

back to top

As you can see from all the above examples, any change comes down to setting a few properties and calling the appropriate method. In fact, most of these are only one line of code!