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

Agent Database

The document defines three Delphi classes: TAgent, TProperty, and TPropertyTable, which manage real estate agents and their properties. TAgent represents an agent with a name and a count of properties, while TProperty represents a property linked to an agent. TPropertyTable manages the collection of properties and agents, allowing properties to be added and randomly assigned to 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

Agent Database

The document defines three Delphi classes: TAgent, TProperty, and TPropertyTable, which manage real estate agents and their properties. TAgent represents an agent with a name and a count of properties, while TProperty represents a property linked to an agent. TPropertyTable manages the collection of properties and agents, allowing properties to be added and randomly assigned to 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
You are on page 1/ 6

```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;
function GetRandomAgent: 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;
var
NewProperty: TProperty;
Agent: TAgent;
begin
Agent := GetRandomAgent;
NewProperty := TProperty.Create(Agent);
FProperties.Add(NewProperty);
end;
function TPropertyTable.GetRandomAgent:
TAgent;
var
RandomIndex: Integer;
begin
Randomize;
RandomIndex :=
Random(FAgents.Count);
Result :=
TAgent(FAgents[RandomIndex]);
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 a random agent,
you can use the following code:
```delphi
var
PropertyTable: TPropertyTable;
Agent: TAgent;
begin
PropertyTable := TPropertyTable.Create;
// Create agents
Agent := TAgent.Create('Agent A');
PropertyTable.FAgents.Add(Agent);
Agent := TAgent.Create('Agent B');
PropertyTable.FAgents.Add(Agent);
Agent := TAgent.Create('Agent C');
PropertyTable.FAgents.Add(Agent);
// Add property and assign it to a random
agent
PropertyTable.AddProperty;
end.
```
This code creates a `TPropertyTable`
instance and adds three agents to the
`FAgents` list. Then, the `AddProperty`
method is called, which generates a
random index to select an agent from the
list and assigns the new property to that
agent.

You might also like