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;
with Restructure1.Field do
begin
FieldType := pxAlpha; // Paradox Alpha type
Name := 'NewFieldName';
Length := 20;
end;
Restructure1.AddField(False); // don't set validity checks
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);
// Drop the third field
Restructure1.DropField(3);
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);
// Move the second field to the fifth position
Restructure1.MoveField(2, 5);
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);
// 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
Check if a field has any validity checks?
var
lVC: Boolean;
lVC := Restructure1.HasValChecks('SomeField');
back to top
// 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');
with Restructure1.ValCheck do
begin
DefaultValue := '16';
MinimumValue := '13';
MaximumValue := '19';
end;
Restructure1.ChangeValCheck('TeenagerAgeField');
// 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');
Check if the table has any referential integrity constraints set?
var
lRI: Boolean;
lRI := Restructure1.HasRefInts;
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');
Remove (delete) a referential integrity constraint?
Restructure1.DropRefInt('RefIntName');
Add a master password to the table (protect the table)?
Restructure1.AddMasterPassword('NewPassword');
Change table's master password?
Restructure1.ChangeMasterPassword('NewPassword');
Remove (delete) table's master password (unprotect the table)?
Restructure1.DropMasterPassword;
// Add a password and set table rights to full
Restructure1.AddAuxPassword('NewAuxiliaryPassword', trFull);
// Change a password and/or change table rights
Restructure1.ChangeAuxPassword('OldAuxiliaryPassword', 'NewAuxiliaryPassword',
trModify);
Remove (delete) an auxiliary password?
Restructure1.DropAuxPassword('ExistingAuxiliaryPassword');
Set field rights for any specific auxiliary
password?
Restructure1.ChangeFieldRights('AuxiliaryPassword', 'FieldName', frReadOnly);
// Set first two fields as primary index
Restructure1.PrimaryIndexFieldCount := 2;
Restructure1.PrimaryIndexFieldCount := 0;
Change the number of fields included
in primary index?
// Set first four fields as primary index
Restructure1.PrimaryIndexFieldCount := 4;
I love this stuff! How do I register?
You can register online by visiting this link. Just follow the simple three-step registration process.
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!