Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 04.11.2016, 21:17   #1
ТанюшкаXXX
 
Регистрация: 04.11.2016
Сообщений: 5
По умолчанию Делфи ComboBox и ListBox

Здравствуйте обитатели форума! У меня проблемы с занесением строк в КомбоБокс и выписания из КомбоБокса в ЛистБок нужных мне строк.
Задача такая, что я хочу занести в КомбоБокс ФИО студентов и их оценки по 3 предметам, потом нужно выписать фамилии тех у кого 2пятерки и 1четверка.

Ошибок много ...
Не знаю как правильно записать не одного студента, нужно ли использовать массив? --> от сюда идут ошибки с типами,
Как правильно вытащить из КомбоБокса строку (я хочу в if сравнивать значения предметов и если подходит все под мои требования, то выводить)

Код:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button2: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Button1: TButton;
    Label4: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Button3: TButton;
    ComboBox1: TComboBox;
    Label6: TLabel;
    Edit5: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Student: array [1..1000] of string;
  a,b,c,d: string;
  n: integer;

implementation
{$R *.dfm}

  procedure TForm1.Button1Click(Sender: TObject);
  begin
  Edit1.Clear;
  Edit2.Clear;
  Edit3.Clear;
  Edit4.Clear;
  end;

procedure TForm1.Button2Click(Sender: TObject);
  var ItemsIndex,i :integer;
      a,b,c,d: string;
begin
 ListBox1.Items.Clear ;// очищаем LisBox
 i:=ComboBox1.ItemIndex+1; //начинаем считывать-порверять с первых оценок
While i<>length do // пока не конец строки
 begin
  if (ComboBox1.ItemsIndex[i]=5) and (ComboBox1.ItemsIndex[i+1]=5) // если 5|5|4
   and (ComboBox1.ItemsIndex[i+2]=4) or                              // или 5|4|5
   (ComboBox1.ItemsIndex[i]=5) and (ComboBox1.ItemsIndex[i+1]=4)    // или 4|5|5
   and (ComboBox1.ItemsIndex[i+2]=5) or
   (ComboBox1.ItemsIndex[i]=4) and (ComboBox1.ItemsIndex[i+1]=5)
   and (ComboBox1.ItemsIndex[i+2]=5)
  then   // то выводим нужную фамилию :
     begin
       ListBox1.Items.Add(Student[i]);
     end;
 end;

procedure TForm1.Button3Click(Sender: TObject);
var m: integer;
 begin
n:=strToInt(Edit5.Text);// сколько студентов введется
for m:=1 to n do //записываем данные в массив и в comboBox1
 //заносим ФИО и оценки по 3 предметам
 ComboBox1.Items.Add.Student[a](Edit1.Text);
 ComboBox1.Items.Add.Student[b](Edit2.Text);
 ComboBox1.Items.Add.Student[c]Edit3.Text);
 ComboBox1.Items.Add.Student[d](Edit4.Text);
end;

end;
ТанюшкаXXX вне форума Ответить с цитированием
Старый 05.11.2016, 11:48   #2
Replicant
Форумчанин
 
Аватар для Replicant
 
Регистрация: 17.08.2009
Сообщений: 139
По умолчанию

Код:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Generics.collections;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Button1: TButton;
    ListBox1: TListBox;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TStudent = class
  public
    Name: String;
    o1, o2, o3: integer;

    function getSum: integer;
    function getStr: string;

    constructor create(AName: String; Ao1, Ao2, Ao3: integer);
  end;

var
  Form1: TForm1;
  StudentList: TList<TStudent>;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
//Кнопка добавить студента
begin
  StudentList.Add(TStudent.create(Edit1.Text,   //Фамилия
    StrToInt(Edit2.Text),   //Оценка 1
    StrToInt(Edit3.Text),   //Оценка 2
    StrToInt(Edit4.Text))); //Оценка 3
    //пихаем студента в ComboBax
  ComboBox1.Items.Add(StudentList.Items[StudentList.Count - 1].Name);
  Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear;
end;

{ TStudent }

constructor TStudent.create(AName: String; Ao1, Ao2, Ao3: integer);
begin
  Name := AName;
  o1 := Ao1;
  o2 := Ao2;
  o3 := Ao3;
end;

procedure TForm1.Button2Click(Sender: TObject);
//Выбираем студентов с оценками 2х5+4 = 14
var i: integer;
const oValue: integer = 14;
begin
  ListBox1.Clear;
  for i:=0 to StudentList.Count-1 do
    if StudentList.Items[i].getSum = oValue then
        ListBox1.Items.Add(StudentList.Items[i].Name);
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  if ComboBox1.Items.Count > 0 then
    Form1.Caption := StudentList.Items[ComboBox1.ItemIndex].getStr;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  StudentList := TList<TStudent>.create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  StudentList.Free;
end;

function TStudent.getStr: string;
begin
  Result:= Name +' '+ o1.ToString+' '+ o2.ToString+' '+ o3.ToString;
end;

function TStudent.getSum: integer;
begin
  Result:= o1+o2+o3;
end;

end.
Replicant вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
ListBox и ComboBox Gyfmod Общие вопросы .NET 0 30.08.2012 17:14
ListBox в combobox ins813 Общие вопросы Delphi 3 06.06.2012 10:32
Listbox and Combobox Lorgan Microsoft Office Excel 3 28.06.2011 02:58
ComboBox и ListBox Martin00 Общие вопросы Delphi 1 08.05.2011 16:36
Вопрос о combobox и listbox Disergslu Microsoft Office Excel 5 08.06.2010 10:06