当前位置:网站首页>Why can't the form be closed? The magic of revealing VFP object references
Why can't the form be closed? The magic of revealing VFP object references
2022-06-25 11:44:00 【VFP of Garfield】
Yesterday was 2022 The first live broadcast class ,XINJIE The teacher gave the lecture , Cats and cats have training classes outside , Just show your face for two minutes , I couldn't watch the whole journey , I can only watch the playback .
This is our harvest , So that everyone's software can be packaged , More classy , Of course, we also need to get more premium .
Come to Garfield's community , There have been too many fox friends surpassing me , So the next will invite you to share , Listen to their knowledge sharing , Your apple + My apple , In exchange , Or an apple , But knowledge , Your knowledge + My knowledge = Double knowledge .
Many fox friends can't write classes yet , Can't use objects , Let's talk about the basics today . The following example is from the network .
“ Object reference ” The concept of
What is? “ Object reference ” Well ? such as , Now we have a form form1, There is a page box on the form pageframe1, There is a table on the first page of the page box grid1, Now? , I want to set the title of the first column to “ First column ”, Set the background color to gray , Under normal circumstances , We have to enter long object hierarchies such as :
thisform.pageframe1.page1.grid1.column1.header1.caption = ” First column “
thisform.pageframe1.page1.grid1.column1.BackColor = RGB(192,192,192)
Use With……EndWith Structure can make the above troublesome input a little easier :
WITH thisform.pageframe1.page1.grid1.column1
.header1.caption = " First column "
.BackColor = RGB(192,192,192)
ENDWITH
Here is the requirement that the code must be continuous , What to do if it is not continuous ?
Put this object into a variable , The variable becomes a part of the object .
LOCAL oColumn ’ Create a pair of tables Column1 References to objects
oColumn = thisform.pageframe1.page1.grid1.column1
oColumn.header1.caption = ” First column “
oColumn.BackColor = RGB(192,192,192)
Here to create oColumn Variable , Then assign it a value Column1 object , In fact, it is not really assigned , In fact, it's just a point , This object is still in its original position , This object references , such , We can operate directly Column1 Object oColumn The variable .
Yes oColumn Any operation of will be reflected in Column1 On the object .
Object references are not equal to ordinary variables
it seems , This so-called “ Object reference ” Variables are no different from ordinary variables . Let's prove it .
Continue with the previous example , However, it is necessary to put the Local Change it to Public, Then put this code into the form's Init Method to go , Run this form and close it , See what happened .
“ The form cannot be closed ! Is it a crash ? Let me press Ctrl+Alt+Del try ……”
“NO! Don't do that !”, No crash , It's just that the reference of the object is making trouble . You can open the debugger to see what happened : stay Local In the window , The variable name of the form is still , Its type is “O”, But its value is already “.NULL.”, in other words : The form has actually been released . And below oColumn Variables are different , Its type is “O”, Value is “ object ”!
reason : Anything created in the form Public Variables are not automatically released when the form is released .
Because we will oColumn Object declared as Public 了 , therefore oColumn Object was not released after closing the form .
We can see it from here : Using the technology of object reference , You can access any object on the form , This is beyond the reach of ordinary variables .
Pass object reference
Let's consider the advantages of object references : An object reference is a variable , So you can pass it like a normal variable , Including passing it to another form ; meanwhile , Object reference is more than just a variable , It can have its own properties 、 event 、 Method —— This means that you are even free to add as many custom attributes to it as you like !
Now let's do a wonderful experiment :
1、 Create a form Form1, Put... On the form 3 Textboxes Text1, Text2, Text3、 One Custom object Custom1、 A command button cmdTransObj, In the command button Click Put the following code into the event :
Do form form2 with this.Custom1
Thisform.Refresh()
2、 Create a schema form Form2( Put the... Of the form WindowType Property is set to “1— Pattern ”), Like form 1 Put it that way 3 Textboxes , Create a custom attribute for the form oFrm1Cust, In the form of
Init Enter the following code in the event :
PARAMETER oCustom
This.oFrm1Cust = oCustom
WITH this
.Text1.Value = . oFrm1Cust.parent.Text1.Value
.Text2.Value = . oFrm1Cust.parent.Text2.Value
.Text3.Value = . oFrm1Cust.parent.Text3.Value
ENDWITH
3、 stay Form2 Add a command button to the cmdReturn, Put the following code :
WITH THISFORM
. oFrm1Cust.parent.Text1.Value = .Text1.Value
. oFrm1Cust.parent.Text2.Value = .Text2.Value
. oFrm1Cust.parent.Text3.Value = .Text3.Value
ENDWITH
THISFORM.Release
OK, Now run Form1, Enter some data in each of the three text boxes , Then press the command button . Forms 1 The data on is now transferred to the form 2 In the three text boxes of , Now put the form 2 Change the data inside , Then press the command button CmdReturn, Forms 2 The changes made in are reflected in the form 1 In the !
You can use this method to easily pass multiple data between forms , And because the data referenced by the object can be modified directly in the called form , You don't even need to return any parameters —— Consider the difficulty of returning an array from a form 、 From one to the other CreateObject( Form class ) Cannot return parameters in the form created by the method of —— You can totally believe : This is the best magic !
More information http://www.sn58.cn
边栏推荐
- 基於Minifilter框架的雙緩沖透明加解密驅動 課程論文+項目源碼
- 文献之有效阅读
- 基于Minifilter框架的双缓冲透明加解密驱动 课程论文+项目源码
- Multiple clicks of the button result in results
- Openfeign uses
- 剑指 Offer II 091. 粉刷房子 : 状态机 DP 运用题
- CFCA安心签接入
- 客从何处来
- Very important very important very important very important very important very important very important very important very important
- What are the ways to simulate and burn programs? (including common tools and usage)
猜你喜欢

时创能源冲刺科创板:拟募资11亿 年营收7亿净利反降36%

Xishan technology rushes to the scientific innovation board: it plans to raise 660million yuan. Guoyijun and his wife have 60% of the voting rights

基于Minifilter框架的双缓冲透明加解密驱动 课程论文+项目源码

Use of Presto visualization client-yanagishima20.0

Detailed explanation of Flink checkpoint specific operation process and summary of error reporting and debugging methods

云原生数据湖以存储、计算、数据管理等能力通过信通院评测认证

Capacity expansion mechanism of Dict Of redis (rehash)

SystemVerilog (XIII) - enumerate data types

Shichuang energy rushes to the scientific innovation board: it plans to raise 1.1 billion yuan, with an annual revenue of 700million yuan and a 36% decrease in net profit

Vulnérabilité à l'injection SQL (contournement)
随机推荐
Customize to prevent repeated submission of annotations (using redis)
Arrays.asList()
Comparator (for arrays.sort)
SQL注入漏洞(类型篇)
Presto Web UI introduction
Is industrial securities a state-owned enterprise? Is it safe to open an account in industrial securities?
SQL注入漏洞(繞過篇)
Under what circumstances will Flink combine operator chains to form operator chains?
Kingbasees plug-in ftutilx of Jincang database
依概率收敛
Translation of meisai C topic in 2022 + sharing of ideas
Design and implementation of university laboratory goods management information system based on SSH
Idea local launch Flink task
Thingpanel publie le client mobile IOT (Multi - images)
按钮多次点击造成结果
建造者模式
Two ways of redis persistence -- detailed explanation of RDB and AOF
Comparison between relu and SIGMOD
GC
Comparable的使用(用于Arrays.sort)