0% found this document useful (0 votes)
9 views6 pages

Databases Delphi

The document presents Delphi code that defines three classes: TAgent, TProperty, and TPropertyTable for managing real estate properties and agents. It includes functionality to add properties to a table and automatically assign them to the agent with the least number of properties. The code demonstrates how to create agents and add properties while ensuring equitable distribution among agents.

Uploaded by

mavislossie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Databases Delphi

The document presents Delphi code that defines three classes: TAgent, TProperty, and TPropertyTable for managing real estate properties and agents. It includes functionality to add properties to a table and automatically assign them to the agent with the least number of properties. The code demonstrates how to create agents and add properties while ensuring equitable distribution among agents.

Uploaded by

mavislossie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sure!

Here's an example of Delphi code


that adds a property to the property table
and automatically assigns it to the agent
with the least number of properties.
```delphi
unit PropertyManagement;
interface
uses
SysUtils, Classes;
type
TAgent = class
private
FName: string;
FProperties: Integer;
public
constructor Create(const AName:
string);
property Name: string read FName;
property Properties: Integer read
FProperties;
end;
TProperty = class
private
FAgent: TAgent;
public
constructor Create(const AAgent:
TAgent);
property Agent: TAgent read FAgent;
end;
TPropertyTable = class
private
FProperties: TList;
FAgents: TList;
public
constructor Create;
destructor Destroy; override;
procedure AddProperty(const AAgent:
TAgent);
function GetAgentWithLeastProperties:
TAgent;
end;
implementation
constructor TAgent.Create(const AName:
string);
begin
FName := AName;
FProperties := 0;
end;
constructor TProperty.Create(const
AAgent: TAgent);
begin
FAgent := AAgent;
AAgent.FProperties :=
AAgent.FProperties + 1;
end;
constructor TPropertyTable.Create;
begin
FProperties := TList.Create;
FAgents := TList.Create;
end;
destructor TPropertyTable.Destroy;
var
I: Integer;
begin
for I := 0 to FProperties.Count - 1 do
TObject(FProperties[I]).Free;
FProperties.Free;
FAgents.Free;
inherited Destroy;
end;
procedure
TPropertyTable.AddProperty(const
AAgent: TAgent);
var
NewProperty: TProperty;
begin
NewProperty :=
TProperty.Create(AAgent);
FProperties.Add(NewProperty);
end;
function
TPropertyTable.GetAgentWithLeastPropert
ies: TAgent;
var
I: Integer;
MinProperties: Integer;
MinAgent: TAgent;
begin
MinProperties := MaxInt;
MinAgent := nil;
for I := 0 to FAgents.Count - 1 do
begin
if TAgent(FAgents[I]).Properties <
MinProperties then
begin
MinProperties :=
TAgent(FAgents[I]).Properties;
MinAgent := TAgent(FAgents[I]);
end;
end;
Result := MinAgent;
end;
end.
```
In this code, we have three classes:
`TAgent`, `TProperty`, and
`TPropertyTable`. The `TAgent` class
represents an agent with a name and a
number of properties. The `TProperty`
class represents a property assigned to an
agent. The `TPropertyTable` class
manages the properties and agents.
To add a property to the property table and
automatically assign it to the agent with the
least number of properties, you can use the
following code:
```delphi
var
PropertyTable: TPropertyTable;
Agent: TAgent;
begin
PropertyTable := TPropertyTable.Create;
// Create agents
Agent := TAgent.Create('Agent A');
PropertyTable.AddProperty(Agent);
Agent := TAgent.Create('Agent B');
PropertyTable.AddProperty(Agent);
Agent := TAgent.Create('Agent C');
PropertyTable.AddProperty(Agent);
// Add property and assign it to the agent
with the least number of properties
Agent :=
PropertyTable.GetAgentWithLeastProperti
es;
PropertyTable.Add

You might also like