Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Party;
- interface
- Type
- TRecordParty = Record
- RIdParty : Integer;
- RName : String[255];
- RPoliticalPosition : String[255];
- End;
- TParty = Class
- IdParty : Integer;
- Name : String[255];
- PoliticalPosition : String[255];
- public
- Constructor Create(IdParty : Integer; Name : String; PoliticalPosition : String);
- Function ConvertToRecord() : TRecordParty;
- Class function ConvertToParty(TR : TRecordParty) : TParty;
- End;
- implementation
- Constructor TParty.Create(IdParty : Integer; Name: string; PoliticalPosition: string);
- begin
- Self.IdParty := IdParty;
- Self.Name := Name;
- Self.PoliticalPosition := PoliticalPosition;
- end;
- Function TParty.ConvertToRecord: TRecordParty;
- var
- ExemplarParty : TRecordParty;
- begin
- with ExemplarParty do
- begin
- RIdParty := Self.IdParty;
- RName := Self.Name;
- RPoliticalPosition := Self.PoliticalPosition;
- ConvertToRecord := ExemplarParty;
- end;
- end;
- Class function TParty.ConvertToParty(TR: TRecordParty): TParty;
- begin
- with TR do
- ConvertToParty := TParty.Create(RIdParty, RName, RPoliticalPosition);
- end;
- end.
- unit CountyNumber;
- interface
- Type
- TRecordCountyNumber = Record
- RIdCountyNumber : Integer;
- RNumber : Integer;
- RName : String[255];
- RRegion : String[255];
- End;
- TCountyNumber = Class
- IdCountyNumber : Integer;
- Number : Integer;
- Name : String[255];
- Region : String[255];
- public
- Constructor Create(IdCountyNumber, Number : Integer; Name, Region : String);
- Function ConvertToRecord() : TRecordCountyNumber;
- Class function ConvertToCountyNumber(TR : TRecordCountyNumber) : TCountyNumber;
- End;
- implementation
- Constructor TCountyNumber.Create(IdCountyNumber: Integer; Number: Integer; Name: string; Region: string);
- begin
- Self.IdCountyNumber := IdCountyNumber;
- Self.Number := Number;
- Self.Name := Name;
- Self.Region := Region;
- end;
- Function TCountyNumber.ConvertToRecord: TRecordCountyNumber;
- var
- ExemplarRCountyNumber : TRecordCountyNumber;
- begin
- with ExemplarRCountyNumber do
- begin
- RIdCountyNumber := Self.IdCountyNumber;
- RNumber := Self.Number;
- RName := Self.Name;
- RRegion := Self.Region;
- ConvertToRecord := ExemplarRCountyNumber;
- end;
- end;
- Class function TCountyNumber.ConvertToCountyNumber(TR: TRecordCountyNumber): TCountyNumber;
- begin
- with TR do
- ConvertToCountyNumber := TCountyNumber.Create(RIdCountyNumber, RNumber, RName, RRegion);
- end;
- end.
- unit Candidate;
- interface
- Type
- TRecordCandidate = Record
- RIdCandidate : Integer;
- RFullname : String[100];
- RPartyId : Integer;
- RCountyNumberId : Integer;
- RAge : Integer;
- RProfession : String[255];
- End;
- TCandidate = class
- IdCandidate : Integer;
- Fullname : String[100];
- PartyId : Integer;
- CountyNumberId : Integer;
- Age : Integer;
- Profession : String[255];
- public
- Constructor Create(IdCandidate : Integer; Fullname : String;
- PartyId, CountyNumberId, Age : Integer; Profession : String);
- Function ConvertToRecord() : TRecordCandidate;
- Class function ConvertToCandidate(TRCandidate : TRecordCandidate) : TCandidate;
- end;
- implementation
- Constructor TCandidate.Create(IdCandidate: Integer; Fullname: string;
- PartyId: Integer; CountyNumberId : Integer; Age: Integer; Profession: string);
- begin
- Self.IdCandidate := IdCandidate;
- Self.Fullname := Fullname;
- Self.PartyId := PartyId;
- Self.CountyNumberId := CountyNumberId;
- Self.Age := Age;
- Self.Profession := Profession;
- end;
- Function TCandidate.ConvertToRecord: TRecordCandidate;
- var
- ExemplarCandidate : TRecordCandidate;
- begin
- ExemplarCandidate.RIdCandidate := Self.IdCandidate;
- ExemplarCandidate.RFullname := Self.Fullname;
- ExemplarCandidate.RPartyId := Self.PartyId;
- ExemplarCandidate.RCountyNumberId := Self.CountyNumberId;
- ExemplarCandidate.RAge := Self.Age;
- ExemplarCandidate.RProfession := Self.Profession;
- ConvertToRecord := ExemplarCandidate;
- end;
- Class function TCandidate.ConvertToCandidate(TRCandidate: TRecordCandidate): TCandidate;
- begin
- With TRCandidate do
- ConvertToCandidate := TCandidate.Create(RIdCandidate, RFullname, RPartyId, RCountyNumberId, RAge, RProfession);
- end;
- end.
- unit BidirectionalParty;
- interface
- uses SysUtils, Party;
- Type
- PPartyList = ^TNode;
- TNode = Record
- Party : TParty;
- Next : PPartyList;
- Prev : PPartyList;
- End;
- TPartyList = Class
- Head : PPartyList;
- Tail : PPartyList;
- Count : Integer;
- public
- Constructor Create();
- Destructor Destroy; override;
- Procedure AddNewParty(Party : TParty);
- Procedure DeleteParty(NodeToDel : PPartyList);
- Procedure DeletePartyByID(PartyID : Integer);
- Procedure SavePartyList(FilePath : String);
- Procedure EditParty(Party : TParty);
- Class Function GetPartyListFromFile(FilePath: string): TPartyList;
- Class Function GetLastPrimaryKey(const TempList : TPartyList) : Integer;
- Class Function GetPartyPrimaryKeyByName(const TempList : TPartyList; Name : String) : Integer;
- Class Function GetPartyNameByPK(const TempList : TPartyList; Key : Integer) : String;
- End;
- implementation
- Constructor TPartyList.Create;
- begin
- Self.Head := NIL;
- Self.Tail := NIL;
- Count := 0;
- end;
- Destructor TPartyList.Destroy;
- var
- Temp : PPartyList;
- begin
- Self.Tail := NIL;
- while Self.Head <> NIL do
- begin
- Temp := Head;
- Head := Head^.Next;
- FreeMem(Temp, SizeOf(TPartyList));
- end;
- inherited;
- end;
- Procedure TPartyList.AddNewParty(Party: TParty);
- var
- NewParty : PPartyList;
- begin
- if Party = NIL then
- Exit;
- New(NewParty);
- NewParty^.Next := NIL;
- NewParty^.Prev := NIL;
- NewParty^.Party := Party;
- if Head = NIL then
- begin
- Head := NewParty;
- Tail := NewParty;
- end
- else
- begin
- Tail^.Next := NewParty;
- NewParty^.Prev := Tail;
- Tail := NewParty;
- end;
- Inc(Count);
- end;
- Procedure TPartyList.DeleteParty(NodeToDel: PPartyList);
- Var
- Temp : PPartyList;
- Begin
- if (Head = NIL) AND (NodeToDel = NIL) then
- Exit;
- if NodeToDel = Head then
- begin
- Head := NodeToDel^.Next;
- if Head <> NIL then
- begin
- Head^.Prev := NIL;
- End
- else
- begin
- Tail := NIL;
- end;
- Dispose(NodeToDel);
- end
- else
- if NodeToDel = Tail then
- begin
- Tail := Tail^.Prev;
- if Tail <> NIL then
- begin
- Tail^.Next := NIL;
- end
- else
- begin
- Head := NIL;
- end;
- Dispose(NodeToDel);
- end
- else
- begin
- Temp := Head;
- while Temp^.Next <> NodeToDel do
- begin
- Temp := Temp^.Next;
- end;
- Temp^.Next := NodeToDel^.Next;
- if NodeToDel^.Next <> NIL then
- begin
- NodeToDel^.Next^.Prev := Temp;
- end;
- Dispose(NodeToDel);
- end;
- Dec(Count);
- end;
- Procedure TPartyList.DeletePartyByID(PartyID: Integer);
- Var
- I : Integer;
- Temp : PPartyList;
- Begin
- if Head = NIL then
- begin
- Exit;
- end;
- Temp := Self.Head;
- I := Temp.Party.IdParty;
- while (Temp <> NIL) AND (I <> PartyID) do
- begin
- Temp := Temp^.Next;
- Inc(I);
- end;
- if Temp = NIL then
- begin
- // В списке не было найдено элемента
- Exit;
- end;
- DeleteParty(Temp);
- end;
- Procedure TPartyList.SavePartyList(FilePath: string);
- var
- FilePartyList : File of TRecordParty;
- TempList : PPartyList;
- TempParty : TRecordParty;
- Begin
- TempList := Self.Head;
- AssignFile(FilePartyList, FilePath);
- Rewrite(FilePartyList);
- while TempList <> NIL do
- begin
- TempParty := TempList^.Party.ConvertToRecord();
- Write(FilePartyList, TempParty);
- TempList := TempList^.Next;
- end;
- Dispose(TempList);
- CloseFile(FilePartyList);
- End;
- Procedure TPartyList.EditParty(Party: TParty);
- var
- TempList : PPartyList;
- begin
- TempList := Self.Head;
- while TempList <> NIL do
- begin
- if TempList.Party.IdParty = Party.IdParty then
- begin
- TempList.Party := Party;
- break;
- end;
- TempList := TempList^.Next;
- end;
- end;
- Class function TPartyList.GetPartyListFromFile(FilePath: string): TPartyList;
- Var
- F: File of TRecordParty;
- TempRecord:TRecordParty;
- TempParty: TParty;
- List: TPartyList;
- Begin
- List := TPartyList.Create; // create an instance of the class
- AssignFile(F, FilePath);
- try
- If (Not(FileExists(FilePath))) then
- begin
- Rewrite(F); // create a new file
- end
- else
- begin
- Reset(F); // open existed file
- end;
- if FileSize(F) <> 0 then
- begin
- while (not Eof(F)) do
- Begin
- Read(F, TempRecord);
- TempParty := TParty.ConvertToParty(TempRecord);
- List.AddNewParty(TempParty);
- End;
- end;
- finally
- CloseFile(F);
- Result := List;
- end;
- End;
- Class Function TPartyList.GetLastPrimaryKey(const TempList : TPartyList): Integer;
- var
- Key : Integer;
- TempHead : PPartyList;
- begin
- Key := -1;
- TempHead := TempList.Head;
- while TempHead <> NIL do
- begin
- if TempHead^.Party.IdParty > Key then
- Key := TempHead^.Party.IdParty;
- TempHead := TempHead^.Next;
- end;
- GetLastPrimaryKey := Key;
- end;
- Class function TPartyList.GetPartyPrimaryKeyByName(const TempList : TPartyList; Name: string): Integer;
- var
- PK : Integer;
- TempHead : PPartyList;
- begin
- PK := 0;
- TempHead := TempList.Head;
- while TempHead <> NIL do
- begin
- if TempHead^.Party.Name = Name then
- PK := TempHead^.Party.IdParty;
- TempHead := TempHead^.Next;
- end;
- GetPartyPrimaryKeyByName := PK;
- end;
- Class function TPartyList.GetPartyNameByPK(const TempList: TPartyList; Key : Integer): string;
- var
- TempHead : PPartyList;
- begin
- TempHead := TempList.Head;
- GetPartyNameByPK := '';
- while TempHead <> NIL do
- begin
- if TempHead^.Party.IdParty = Key then
- GetPartyNameByPK := TempHead^.Party.Name;
- TempHead := TempHead^.Next;
- end;
- end;
- end.
- unit BidirectionalCountyNumber;
- interface
- uses SysUtils, CountyNumber;
- Type
- PCountyNumberList = ^TNode;
- TNode = record
- CountyNumber : TCountyNumber;
- Next : PCountyNumberList;
- Prev : PCountyNumberList;
- end;
- TCountyNumberList = class
- Head : PCountyNumberList;
- Tail : PCountyNumberList;
- Count : Integer;
- public
- Constructor Create();
- Destructor Destroy; override;
- Procedure AddNewCountyNumber(CountyNumber : TCountyNumber);
- Procedure DeleteCountyNumber(NodeToDel : PCountyNumberList);
- Procedure DeleteCountyNumberByID (CountyNumberId : Integer);
- Procedure SaveCountyNumberList(FilePath: string);
- Procedure EditCountyNumber(CountyNumber : TCountyNumber);
- Class Function GetCountyNumberListFromFile(FilePath: string): TCountyNumberList;
- Class Function GetLastPrimaryKey(const TempList : TCountyNumberList) : Integer;
- Class Function GetCountyNumberByPK(const TempList : TCountyNumberList; Key : Integer) : Integer;
- Class Function GetGetCountyNumberPrimaryKeyByNumber(const TempList : TCountyNumberList; Number : Integer) : Integer;
- end;
- implementation
- Destructor TCountyNumberList.Destroy;
- var
- Temp : PCountyNumberList;
- begin
- Self.Tail := NIL;
- while Self.Head <> NIL do
- begin
- Temp := Head;
- Head := Head^.Next;
- FreeMem(Temp, SizeOf(TCountyNumberList));
- end;
- inherited;
- end;
- Constructor TCountyNumberList.Create;
- begin
- Self.Head := NIL;
- Self.Tail := NIL;
- Count := 0;
- end;
- Procedure TCountyNumberList.AddNewCountyNumber(CountyNumber: TCountyNumber);
- var
- NewCountyNumber : PCountyNumberList;
- begin
- if CountyNumber = NIL then
- Exit;
- New(NewCountyNumber);
- NewCountyNumber^.Next := NIL;
- NewCountyNumber^.Prev := NIL;
- NewCountyNumber^.CountyNumber := CountyNumber;
- if Head = NIL then
- begin
- Head := NewCountyNumber;
- Tail := NewCountyNumber;
- end
- else
- begin
- Tail^.Next := NewCountyNumber;
- NewCountyNumber^.Prev := Tail;
- Tail := NewCountyNumber;
- end;
- Inc(Count);
- end;
- Procedure TCountyNumberList.DeleteCountyNumber(NodeToDel: PCountyNumberList);
- Var
- Temp : PCountyNumberList;
- Begin
- if (Head = NIL) AND (NodeToDel = NIL) then
- Exit;
- if NodeToDel = Head then
- begin
- Head := NodeToDel^.Next;
- if Head <> NIL then
- begin
- Head^.Prev := NIL;
- End
- else
- begin
- Tail := NIL;
- end;
- Dispose(NodeToDel);
- end
- else
- if NodeToDel = Tail then
- begin
- Tail := Tail^.Prev;
- if Tail <> NIL then
- begin
- Tail^.Next := NIL;
- end
- else
- begin
- Head := NIL;
- end;
- Dispose(NodeToDel);
- end
- else
- begin
- Temp := Head;
- while Temp^.Next <> NodeToDel do
- begin
- Temp := Temp^.Next;
- end;
- Temp^.Next := NodeToDel^.Next;
- if NodeToDel^.Next <> NIL then
- begin
- NodeToDel^.Next^.Prev := Temp;
- end;
- Dispose(NodeToDel);
- end;
- Dec(Count);
- end;
- Procedure TCountyNumberLIst.DeleteCountyNumberByID(CountyNumberId: Integer);
- Var
- I : Integer;
- Temp : PCountyNumberList;
- Begin
- if Head = NIL then
- begin
- Exit;
- end;
- Temp := Self.Head;
- I := Temp.CountyNumber.IdCountyNumber;
- while (Temp <> NIL) AND (I <> CountyNumberID) do
- begin
- Temp := Temp^.Next;
- Inc(I);
- end;
- if Temp = NIL then
- begin
- // В списке не было найдено элемента
- Exit;
- end;
- DeleteCountyNumber(Temp);
- end;
- Procedure TCountyNumberList.SaveCountyNumberList(FilePath: string);
- var
- FileCountyNumberList : File of TRecordCountyNumber;
- TempList : PCountyNumberList;
- TempCountyNumber : TRecordCountyNumber;
- Begin
- TempList := Self.Head;
- AssignFile(FileCountyNumberList, FilePath);
- Rewrite(FileCountyNumberList);
- while TempList <> NIL do
- begin
- TempCountyNumber := TempList^.CountyNumber.ConvertToRecord();
- Write(FileCountyNumberList, TempCountyNumber);
- TempList := TempList^.Next;
- end;
- CloseFile(FileCountyNumberList);
- End;
- Procedure TCountyNumberList.EditCountyNumber(CountyNumber: TCountyNumber);
- var
- TempList : PCountyNumberList;
- begin
- TempList := Self.Head;
- while TempList <> NIL do
- begin
- if TempList.CountyNumber.IdCountyNumber = CountyNumber.IdCountyNumber then
- begin
- TempList.CountyNumber := CountyNumber;
- break;
- end;
- TempList := TempList^.Next;
- end;
- end;
- Class function TCountyNumberList.GetCountyNumberListFromFile(FilePath: string): TCountyNumberList;
- Var
- F: File of TRecordCountyNumber;
- TempRecord:TRecordCountyNumber;
- TempCountyNumber: TCountyNumber;
- List: TCountyNumberList;
- Begin
- List := TCountyNumberList.Create; // create an instance of the class
- AssignFile(F, FilePath);
- try
- If (Not(FileExists(FilePath))) then
- begin
- Rewrite(F); // create a new file
- end
- else
- begin
- Reset(F); // open existed file
- end;
- if FileSize(F) <> 0 then
- begin
- while (not Eof(F)) do
- Begin
- Read(F, TempRecord);
- TempCountyNumber := TCountyNumber.ConvertToCountyNumber(TempRecord);
- List.AddNewCountyNumber(TempCountyNumber);
- End;
- end;
- finally
- CloseFile(F);
- Result := List;
- end;
- End;
- Class function TCountyNumberList.GetLastPrimaryKey(const TempList: TCountyNumberList): Integer;
- var
- Key : Integer;
- TempHead : PCountyNumberList;
- begin
- Key := -1;
- TempHead := TempList.Head;
- while TempHead <> NIL do
- begin
- if TempHead^.CountyNumber.IdCountyNumber > Key then
- Key := TempHead^.CountyNumber.IdCountyNumber;
- TempHead := TempHead^.Next;
- end;
- GetLastPrimaryKey := Key;
- end;
- Class function TCountyNumberList.GetCountyNumberByPK(const TempList: TCountyNumberList; Key: Integer): Integer;
- var
- TempHead : PCountyNumberList;
- begin
- TempHead := TempList.Head;
- GetCountyNumberByPK := -1;
- while TempHead <> NIL do
- begin
- if TempHead^.CountyNumber.IdCountyNumber = Key then
- GetCountyNumberByPK := TempHead^.CountyNumber.Number;
- TempHead := TempHead^.Next;
- end;
- end;
- Class function TCountyNumberList.GetGetCountyNumberPrimaryKeyByNumber(const TempList: TCountyNumberList; Number: Integer): Integer;
- var
- PK : Integer;
- TempHead : PCountyNumberList;
- begin
- PK := 0;
- TempHead := TempList.Head;
- while TempHead <> NIL do
- begin
- if TempHead^.CountyNumber.Number = Number then
- PK := TempHead^.CountyNumber.IdCountyNumber;
- TempHead := TempHead^.Next;
- end;
- GetGetCountyNumberPrimaryKeyByNumber := PK;
- end;
- end.
- unit BidirectionalCandidate;
- interface
- uses SysUtils, Party, Candidate;
- Type
- PCandidateList = ^TNode;
- TNode = Record
- Candidate : TCandidate;
- Next : PCandidateList;
- Prev : PCandidateList;
- End;
- TCandidateList = Class
- Head : PCandidateList;
- Tail : PCandidateList;
- Count : Integer;
- public
- Constructor Create();
- Destructor Destroy; override;
- Procedure AddNewCandidate(Candidate : TCandidate);
- Procedure DeleteCandidate(NodeToDel : PCandidateList);
- Procedure DeleteCandidateByID(CandidateID : Integer);
- Procedure SaveCandidateList(FilePath : String);
- Procedure EditCandidate(Candidate : TCandidate);
- Class Function GetCandidateListFromFile(FilePath: string): TCandidateList;
- Class Function GetLastPrimaryKey(const TempList : TCandidateList) : Integer;
- End;
- implementation
- Constructor TCandidateList.Create;
- begin
- Self.Head := NIL;
- Self.Tail := NIL;
- Self.Count := 0;
- end;
- Destructor TCandidateList.Destroy;
- var
- TempNode : PCandidateList;
- begin
- Self.Tail := NIL;
- while Self.Head <> NIL do
- begin
- TempNode := Head;
- Head := Head^.Next;
- FreeMem(TempNode, SizeOf(TCandidateList));
- end;
- inherited;
- end;
- Procedure TCandidateList.AddNewCandidate(Candidate: TCandidate);
- var
- NewCandidate : PCandidateList;
- begin
- if Candidate = NIL then // Если экземпляр кандидата не равен NIL
- Exit;
- New(NewCandidate); // Выделение памяти для нового узла списка
- // Инициализация узла
- NewCandidate^.Next := NIL;
- NewCandidate^.Prev := NIL;
- NewCandidate^.Candidate := Candidate;
- if Head = NIL then // Если голова списка = NIL
- begin
- Head := NewCandidate;
- Tail := NewCandidate;
- end
- else // Если голова списка <> NIL
- begin
- Tail^.Next := NewCandidate;
- NewCandidate^.Prev := Tail;
- Tail := NewCandidate;
- end;
- Inc(Count); // Инкрементирование счетчика записей в списке
- end;
- Procedure TCandidateList.DeleteCandidate(NodeToDel: PCandidateList);
- Var
- Temp : PCandidateList;
- Begin
- // Если список пустой
- if (Head = NIL) AND (NodeToDel = NIL) then
- Exit;
- // Если узел к удалению = голове
- if NodeToDel = Head then
- begin
- Head := NodeToDel^.Next; // Голове присвоить следующий узел
- // Если голова не пустая
- if Head <> NIL then
- begin
- Head^.Prev := NIL;
- End
- else // Если голова пустая
- begin
- Tail := NIL;
- end;
- // Уничтожение объекта
- Dispose(NodeToDel);
- end
- else // Если узел к удалению = хвосту
- if NodeToDel = Tail then
- begin
- // Присвоить хвосту предыдущий элемент
- Tail := Tail^.Prev;
- // Если хвост не пустой
- if Tail <> NIL then
- begin
- Tail^.Next := NIL;
- end
- else // Если хвост пустой
- begin
- Head := NIL;
- end;
- // Уничтожение объекта
- Dispose(NodeToDel);
- end
- else // Если узел к удалению <> HEAD and TAIL
- begin
- Temp := Head;
- // Пока Next текущего узла <> узлу к удалению
- while Temp^.Next <> NodeToDel do
- begin
- Temp := Temp^.Next;
- end;
- Temp^.Next := NodeToDel^.Next;
- // Если NEXT узла к удалению <> NIL
- if NodeToDel^.Next <> NIL then
- begin
- NodeToDel^.Next^.Prev := Temp;
- end;
- // Уничтожение объекта
- Dispose(NodeToDel);
- end;
- // Уменьшить счетчик количества записей
- Dec(Count);
- end;
- Procedure TCandidateList.DeleteCandidateByID(CandidateID: Integer);
- Var
- I : Integer;
- Temp : PCandidateList;
- Begin
- if Head = NIL then
- begin
- Exit;
- end;
- Temp := Self.Head;
- I := Temp.Candidate.IdCandidate;
- while (Temp <> NIL) AND (I <> CandidateID) do
- begin
- Temp := Temp^.Next;
- Inc(I);
- end;
- if Temp = NIL then
- begin
- // В списке не было найдено элемента
- Exit;
- end;
- DeleteCandidate(Temp);
- end;
- Procedure TCandidateList.SaveCandidateList(FilePath: string);
- var
- FileCandidateList : File of TRecordCandidate;
- TempList : PCandidateList;
- TempCandidate : TRecordCandidate;
- Begin
- // Присвоить узлу ссылку на голову
- TempList := Self.Head;
- // Связка файла с путем к файлу
- AssignFile(FileCandidateList, FilePath);
- // Открытие файла для записи
- Rewrite(FileCandidateList);
- // Пока текущий узел не равен NIL
- while TempList <> NIL do
- begin
- TempCandidate := TempList^.Candidate.ConvertToRecord();
- // Запись текущего кандидата в файл
- Write(FileCandidateList, TempCandidate);
- // Переход к следующему узлу
- TempList := TempList^.Next;
- end;
- // Закрытие файла
- CloseFile(FileCandidateList);
- End;
- Procedure TCandidateList.EditCandidate(Candidate: TCandidate);
- var
- TempList : PCandidateList;
- begin
- // Присвоить голову
- TempList := Self.Head;
- // Пока текущий узел не равен NIL
- while TempList <> NIL do
- begin
- // Если ID текущего кандидата равно ID переданному кандидату
- if TempList.Candidate.IdCandidate = Candidate.IdCandidate then
- begin
- // Присвоить текущему узлу параметр переданного кандидата
- TempList.Candidate := Candidate;
- // Выйти из цикла
- break;
- end;
- // Перейти к следующему узлу
- TempList := TempList^.Next;
- end;
- end;
- Class function TCandidateList.GetCandidateListFromFile(FilePath: string): TCandidateList;
- Var
- F: File of TRecordCandidate;
- TempRecord:TRecordCandidate;
- TempCandidate: TCandidate;
- List: TCandidateList;
- Begin
- List := TCandidateList.Create;
- AssignFile(F, FilePath);
- try
- If Not (FileExists(FilePath)) then
- begin
- Rewrite(F);
- end
- else
- begin
- Reset(F);
- end;
- if FileSize(F) <> 0 then
- begin
- while (not Eof(F)) do
- Begin
- Read(F, TempRecord);
- TempCandidate := TCandidate.ConvertToCandidate(TempRecord);
- List.AddNewCandidate(TempCandidate);
- End;
- end;
- finally
- CloseFile(F);
- Result := List;
- end;
- End;
- Class Function TCandidateList.GetLastPrimaryKey(const TempList : TCandidateList): Integer;
- var
- Key : Integer;
- TempHead : PCandidateList;
- begin
- Key := -1;
- TempHead := TempList.Head;
- while TempHead <> NIL do
- begin
- if TempHead^.Candidate.IdCandidate > Key then
- Key := TempHead^.Candidate.IdCandidate;
- TempHead := TempHead^.Next;
- end;
- GetLastPrimaryKey := Key;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement