Я зделал так и всё получилось, это модуль формы сообщения, а вызывается из главной формы: Модуль ещё не доработан, так что пока всё убого )
| Код | unit AlarmMessageUnit;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, MPlayer, Buttons, MMSystem, ComCtrls, SettingUnit;
type TFormMessage = class(TForm) MemoMessage: TMemo; SpeedButton1: TSpeedButton; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormCreate(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormPaint(Sender: TObject);
private { Private declarations } public procedure CreateMessage(Alarm : TClock; IndexList : TListItem); { Public declarations } end;
var FormMessage: TFormMessage; ReserveVol : LongWord; implementation
uses NewAlarmClock;
{$R *.dfm}
procedure TFormMessage.CreateMessage(Alarm : TClock; IndexList : TListItem); begin if Alarm.FModeMessage = MINI_1 then begin ReserveVol := 0; Self.Width := 255; Self.Height := 222;
Self.MemoMessage.Color := Alarm.FAppearanceMsg.ColorBackground; Self.Color := Alarm.FAppearanceMsg.ColorBackground; Self.AlphaBlendValue := Alarm.FAppearanceMsg.AlphaBlendValue; Self.MemoMessage.Font.Name := Alarm.FAppearanceMsg.FontText; Self.MemoMessage.Font.Color := Alarm.FAppearanceMsg.FontColor; Self.MemoMessage.Font.Size := Alarm.FAppearanceMsg.FontSize;
Self.MemoMessage.Clear; Self.MemoMessage.Text := Alarm.FTextMessage;
if Alarm.FMusicEnabled then //если воспроизведение музыки выбрано, то... begin Form1.MP.FileName := Alarm.FMusicWay; Form1.MP.Open; Form1.MP.Play; end;
if Alarm.FChangeSound then //если изменение громкости выбрано, то... begin ReserveVol := FormNewClock.GetVolume; waveOutSetVolume(WAVE_MAPPER,Alarm.FVolume); end; end; end;
procedure TFormMessage.FormClose(Sender: TObject; var Action: TCloseAction); begin Form1.CountMsgForms := Form1.CountMsgForms - 1; if not Form1.MsgFormsExists then begin Form1.TimerAlarms.Enabled := False; Form1.TimerMsgFormExists.Enabled := True; end; end;
procedure TFormMessage.FormCreate(Sender: TObject); begin Form1.CountMsgForms := Form1.CountMsgForms + 1; //количество созданных форм, думал поможет в одном вопросе... не помогло. end;
procedure TFormMessage.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ReleaseCapture; SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION,0); end;
procedure TFormMessage.FormPaint(Sender: TObject); var p : TPoint; begin p.X := 0; p.Y := 32; Self.Canvas.Rectangle(0, 0, Self.Width, Self.Height); Self.Canvas.PenPos := p; Self.Canvas.Pen.Color := clBlack; Self.Canvas.Pen.Style := psDot; Self.Canvas.LineTo(Self.Width, 32); end;
procedure TFormMessage.SpeedButton1Click(Sender: TObject); var I: Integer; M : array of integer; begin Form1.TimerAlarms.Enabled := False; if Form1.MP.Mode = mpPlaying then begin Form1.MP.Stop; Form1.MP.Close; end; if ReserveVol <> 0 then begin waveOutSetVolume(WAVE_MAPPER, ReserveVol); end; Self.Close; end;
end.
|
Вот что я поменял в главной форме:
| Код | procedure TForm1.TimerAlarmsTimer(Sender: TObject); var I : integer; begin DateTimeNow := Now; DecodeDate(DateTimeNow, YearNow, MonthNow, DayNow); DecodeTime(DateTimeNow, HourNow, MinNow, SecNow, MilSecNow); for I := 0 to (ListViewAlarm.Items.Count - 1) do begin if TClock(ListViewAlarm.Items.Item[I].Data).CheckTime then begin if MP.Mode = mpPlaying then begin MP.Stop; MP.Close; end; try FormMsg := TFormMessage.Create(Application.MainForm); //Тут поменял FormMsg.CreateMessage(TClock(ListViewAlarm.Items.Item[I].Data), ListViewAlarm.Items.Item[I]); //Тут поменял FormMsg.Show; //Тут поменял except ShowMessage('При создании формы сообщения произошла ошибка'); end; end; end; end;
|
переменную FormMsg объявил в главном модуле, но оказывается проблемы были из-за самого модуля сообщения, там где сейчас написано Self, было FormMessage, вот так решил проблему |