<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774374</guid>
        <pubDate>Thu, 19 Jul 2018 08:38:38 +0000</pubDate>
        <title>Обработчик событий в динамически созданном объекте</title>
        <link>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774374</link>
        <description><![CDATA[Fr0sT: В теории можно самому реализовать ShowModal, крутя выборку сообщений, ловить соответствующий click и обрабатывать его. Но это маразм. Я бы посоветовал не жадиться и выделить этот диалог в самостоятельный класс со всеми приличествующими атрибутами. Потому что через месяц ты захочешь прикрутить, к примеру, показ баллуна и дизейбл кнопки при вводе некорректного символа, и цикл повторится. <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2018-07-19T11:39:49+03:00">19.07.18, 08:39</time></span></span><br>
Также можно подменить WindowProc, но тут тоже всё внутри процедуры не упакуешь.]]></description>
        <author>Fr0sT</author>
        <category>Delphi: Разработка компонентов</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774364</guid>
        <pubDate>Thu, 19 Jul 2018 04:52:24 +0000</pubDate>
        <title>Обработчик событий в динамически созданном объекте</title>
        <link>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774364</link>
        <description><![CDATA[Gonarh: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=413232&view=findpost&p=3774363'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>MBo &#064; <time class="tag-quote__quoted-time" datetime="2018-07-19T03:32:31+00:00">19.07.18, 03:32</time></span><div class='quote '>Обработчик события (procedure MyOnClick) должен быть <strong class='tag-b'>методом объекта</strong>, а не регулярной процедурой<br>
...<br>
Как видно по TMainForm - объект имеется, вот его методом и сделать MyOnClick<br>
</div></div><br>
Можно присобачить динамически к чекбоксу.<br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=413232&view=findpost&p=3774361'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>User32 &#064; <time class="tag-quote__quoted-time" datetime="2018-07-18T21:06:12+00:00">18.07.18, 21:06</time></span><div class='quote '>Собственно как это сделать внутри функции?</div></div><br>
Внутри никак, снаружи - элементарно<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure cbxClick(Sender: TObject);</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;if (Sender as TCheckBox).Checked then showmessage(&#39;+&#39;) else showmessage(&#39;-&#39;);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">function TMainForm.MyInputQuery(const ACaption, APrompt, AButtonOk, AButtonCancel: string;</div><div class="code_line">&nbsp;&nbsp;var Value: string;EventCBX:Pointer=nil): Boolean;</div><div class="code_line">var</div><div class="code_line">...</div><div class="code_line">&nbsp;&nbsp;NE:TNotifyEvent;</div><div class="code_line">begin</div><div class="code_line">...</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;CheckBox := TCheckBox.Create(Form);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;with CheckBox do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Parent := Form;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Left := Prompt.Left;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Top := Edit.Top + Edit.Height + 6;//15;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Width := MulDiv(113, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := &#39;Скрыть пароль&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Checked := True;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;State := cbChecked;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if EventCBX&#60;&#62;nil then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;with TMethod(NE) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Code:=EventCBX;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Data:=Pointer(CheckBox);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OnClick:=NE;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">...</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">....</div><div class="code_line">MyInputQuery(ACaption, APrompt, AButtonOk, AButtonCancel, Value, @cbxClick);</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script> <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2018-07-19T04:54:34+00:00">19.07.18, 04:54</time></span></span><br>
<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=413232&view=findpost&p=3774361'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>User32 &#064; <time class="tag-quote__quoted-time" datetime="2018-07-18T21:06:12+00:00">18.07.18, 21:06</time></span><div class='quote '>Причина такого подхода заключается в довольно частом и универсальном использовании InputQuery.</div></div><br>
У дураков мысли сходятся, у мну такая же функция есть )))]]></description>
        <author>Gonarh</author>
        <category>Delphi: Разработка компонентов</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774363</guid>
        <pubDate>Thu, 19 Jul 2018 03:32:31 +0000</pubDate>
        <title>Обработчик событий в динамически созданном объекте</title>
        <link>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774363</link>
        <description><![CDATA[MBo: Обработчик события (procedure MyOnClick) должен быть <strong class='tag-b'>методом объекта</strong>, а не регулярной процедурой и тем более не вложенной.<br>
<br>
Как видно по <span class='tag-u'>TMainForm </span>- объект имеется, вот его методом и сделать  MyOnClick]]></description>
        <author>MBo</author>
        <category>Delphi: Разработка компонентов</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774361</guid>
        <pubDate>Wed, 18 Jul 2018 21:06:12 +0000</pubDate>
        <title>Обработчик событий в динамически созданном объекте</title>
        <link>https://forum.sources.ru/index.php?showtopic=413232&amp;view=findpost&amp;p=3774361</link>
        <description><![CDATA[User32: Друзья, нужна помощь в укращении InputQuery.<br>
Решил немного переписать диалоговое окно InputQuery из Dialogs.pas, добавив CheckBox.<br>
И тут встала проблема обработки события OnClick у CheckBox...<br>
Собственно как это сделать внутри функции?<br>
<br>
Крод:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">function TMainForm.MyInputQuery(const ACaption, APrompt, AButtonOk, AButtonCancel: string;</div><div class="code_line">&nbsp;&nbsp;var Value: string): Boolean;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Form: TForm;</div><div class="code_line">&nbsp;&nbsp;Prompt: TLabel;</div><div class="code_line">&nbsp;&nbsp;Edit: TEdit;</div><div class="code_line">&nbsp;&nbsp;CheckBox: TCheckBox;</div><div class="code_line">&nbsp;&nbsp;DialogUnits: TPoint;</div><div class="code_line">&nbsp;&nbsp;ButtonTop, ButtonWidth, ButtonHeight: Integer;</div><div class="code_line">&nbsp;</div><div class="code_line">function GetAveCharSize(Canvas: TCanvas): TPoint;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;I: Integer;</div><div class="code_line">&nbsp;&nbsp;Buffer: array[0..51] of Char;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;for I := 0 to 25 do Buffer[I] := Chr(I + Ord(&#39;A&#39;));</div><div class="code_line">&nbsp;&nbsp;for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord(&#39;a&#39;));</div><div class="code_line">&nbsp;&nbsp;GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));</div><div class="code_line">&nbsp;&nbsp;Result.X := Result.X div 52;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure MyOnClick(Sender: TObject);</div><div class="code_line">begin</div><div class="code_line">&nbsp;if(CheckBox.Checked) then</div><div class="code_line">&nbsp;&nbsp;Edit.PasswordChar := #42</div><div class="code_line">&nbsp;else</div><div class="code_line">&nbsp;&nbsp;Edit.PasswordChar := #0;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := False;</div><div class="code_line">&nbsp;&nbsp;Form := TForm.Create(Application);</div><div class="code_line">&nbsp;&nbsp;with Form do</div><div class="code_line">&nbsp;&nbsp; &nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Canvas.Font := Font;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;DialogUnits := GetAveCharSize(Canvas);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;BorderStyle := bsDialog;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Caption := ACaption;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ClientWidth := MulDiv(180, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Position := poScreenCenter;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Prompt := TLabel.Create(Form);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;with Prompt do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Parent := Form;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := APrompt;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Left := MulDiv(8, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Top := MulDiv(8, DialogUnits.Y, 8);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;WordWrap := True;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Edit := TEdit.Create(Form);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;with Edit do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Parent := Form;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Left := Prompt.Left;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Top := Prompt.Top + Prompt.Height + 5;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Width := MulDiv(164, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;MaxLength := 255;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;PasswordChar := &#39;*&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Value;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SelectAll;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;CheckBox := TCheckBox.Create(Form);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;with CheckBox do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Parent := Form;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Left := Prompt.Left;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Top := Edit.Top + Edit.Height + 6;//15;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Width := MulDiv(113, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := &#39;Скрыть пароль&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Checked := True;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;State := cbChecked;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;OnClick := MyOnClick; //проблема тут!!!</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ButtonTop := Edit.Top + Edit.Height + 25;//15;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ButtonWidth := MulDiv(50, DialogUnits.X, 4);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;ButtonHeight := MulDiv(14, DialogUnits.Y, 8);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;with TButton.Create(Form) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Parent := Form;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := AButtonOk;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ModalResult := mrOk;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Default := True;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ButtonHeight);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;with TButton.Create(Form) do</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Parent := Form;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := AButtonCancel;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ModalResult := mrCancel;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Cancel := True;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, //Edit.Top + Edit.Height + 15,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ButtonWidth, ButtonHeight);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Form.ClientHeight := Top + Height + 13;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if ShowModal = mrOk then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Value := Edit.Text;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Result := True;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;finally</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Form.Free;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div><br>
<span class="b-attach" data-size="3798" data-hits="881" data-attach-id="58952" data-attach-post-id="3774361">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=3774361&amp;attach_id=58952' title='Скачать файл' target='_blank'>____________________.png</a> (, : 881)
		</span><br>
<br>
Причина такого подхода заключается в довольно частом и универсальном использовании InputQuery.]]></description>
        <author>User32</author>
        <category>Delphi: Разработка компонентов</category>
      </item>
	
      </channel>
      </rss>
	