Ver Mensaje Individual
  #1  
Antiguo 16-07-2014
Avatar de cl2raul
cl2raul cl2raul is offline
Miembro
 
Registrado: sep 2008
Ubicación: La Habana, Cuba
Posts: 88
Reputación: 16
cl2raul Va por buen camino
Optimización de código

hola tengo hecho este programa para android, pero quiero q lo corran y me digan pq cuando aumento el periodo se demora muchísimo en dar los números, y lo mas importante, ayúdenme a optimizar este codigo...

Código Delphi [-]
unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  FMX.Edit, FMX.DateTimeCtrls, FMX.Layouts, FMX.ListBox, System.StrUtils, System.DateUtils;

type
  TForm1 = class(TForm)
    CalendarEdit1: TCalendarEdit;
    Button1: TButton;
    CalendarEdit2: TCalendarEdit;
    Label1: TLabel;
    Label2: TLabel;
    ListBox2: TListBox;
    Label3: TLabel;
    Label4: TLabel;
    ComboBox1: TComboBox;
    ListBox1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    periodoD, periodoN: integer;
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
begin
  CalendarEdit1.Date:=Now;
  case ComboBox1.ItemIndex of
    0:begin
        periodoD:=DaysInMonth(CalendarEdit1.Date);
        periodoN:=DaysInMonth(CalendarEdit2.Date);
      end;
    1:begin
        periodoD:=(DaysInYear(CalendarEdit1.Date) div 2);
        periodoN:=(DaysInYear(CalendarEdit2.Date) div 2);
      end;
    2:begin
        periodoD:=(DaysInYear(CalendarEdit1.Date) div 2);
        periodoN:=(DaysInYear(CalendarEdit2.Date) div 2);
      end;
    3:begin
        periodoD:=DaysInYear(CalendarEdit1.Date);
        periodoN:=DaysInYear(CalendarEdit2.Date);
      end;
  end;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
  case ComboBox1.ItemIndex of
    0:begin
        periodoD:=DaysInMonth(CalendarEdit1.Date);
        periodoN:=DaysInMonth(CalendarEdit2.Date);
      end;
    1:begin
        periodoD:=(DaysInYear(CalendarEdit1.Date) div 2);
        periodoN:=(DaysInYear(CalendarEdit2.Date) div 2);
      end;
    2:begin
        periodoD:=(DaysInYear(CalendarEdit1.Date) div 2);
        periodoN:=(DaysInYear(CalendarEdit2.Date) div 2);
      end;
    3:begin
        periodoD:=DaysInYear(CalendarEdit1.Date);
        periodoN:=DaysInYear(CalendarEdit2.Date);
      end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  fechadiurna, fechanocturna:Integer;
  weekD, weekN:Variant;
  semanaD, semanaN:string;
begin
  ListBox1.Clear;       ListBox2.Clear;
  ListBox1.Items.Add(DateToStr(CalendarEdit1.Date));
  for fechadiurna:=0 to periodoD do
    begin
      weekD:=DayOfTheWeek(
        IncDay(StrToDate(LeftStr(ListBox1.Items[fechadiurna],8)), 4)
      );
      case weekD of
      1:semanaD:='LUN';
      2:semanaD:='MAR';
      3:semanaD:='MIE';
      4:semanaD:='JUE';
      5:semanaD:='VIE';
      6:semanaD:='SAB';
      7:semanaD:='DOM';
      end;
      ListBox1.Items.Add(
        DateToStr(IncDay(StrToDate(LeftStr(ListBox1.Items[fechadiurna],8)), 4))
        +'-'+
        semanaD
      );
    end;

  ListBox2.Items.Add(DateToStr(CalendarEdit2.Date));
  for fechanocturna:=0 to periodoN do
    begin
      weekN:=DayOfTheWeek(
        IncDay(StrToDate(LeftStr(ListBox2.Items[fechanocturna],8)), 4)
      );
      case weekN of
      1:semanaN:='LUN';
      2:semanaN:='MAR';
      3:semanaN:='MIE';
      4:semanaN:='JUE';
      5:semanaN:='VIE';
      6:semanaN:='SAB';
      7:semanaN:='DOM';
      end;
      ListBox2.Items.Add(
        DateToStr(IncDay(StrToDate(LeftStr(ListBox2.Items[fechanocturna],8)), 4))
        +'-'+
        semanaN
      );
    end;
end;

end.
Responder Con Cita